Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwrite update override columns on PUT /dataset #20862

Merged
merged 11 commits into from
Jul 30, 2022

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Jul 26, 2022

SUMMARY

Update logic for overriding columns on update. Initially was getting the following error when trying to make an update with column name that are the same:

sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: table_columns.column_name, table_columns.table_id
[SQL: INSERT INTO table_columns (uuid, created_on, changed_on, column_name, verbose_name, is_active, type, advanced_data_type, groupby, filterable, description, table_id, is_dttm, expression, python_date_format, extra, created_by_fk, changed_by_fk) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: (<memory at 0x7f9480379b80>, '2022-07-27 01:33:05.056116', '2022-07-27 01:33:05.056122', 'YEAR', None, 1, 'INT', None, 1, 1, None, 25, 0, None, None, None, 1, 1)]
(Background on this error at: https://sqlalche.me/e/14/gkpj)

With this new pattern, users will be able to overwrite a dataset event if the columns are named the same.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jul 26, 2022

Codecov Report

Merging #20862 (4d2a242) into master (1a8c28d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master   #20862   +/-   ##
=======================================
  Coverage   66.30%   66.30%           
=======================================
  Files        1758     1758           
  Lines       67065    67073    +8     
  Branches     7122     7122           
=======================================
+ Hits        44468    44476    +8     
  Misses      20767    20767           
  Partials     1830     1830           
Flag Coverage Δ
hive 53.24% <0.00%> (-0.02%) ⬇️
mysql 81.00% <100.00%> (+<0.01%) ⬆️
postgres 81.07% <100.00%> (+<0.01%) ⬆️
presto 53.14% <0.00%> (-0.02%) ⬇️
python 81.55% <100.00%> (+<0.01%) ⬆️
sqlite 79.65% <0.00%> (-0.02%) ⬇️
unit 50.58% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/datasets/commands/update.py 94.04% <100.00%> (+0.07%) ⬆️
superset/datasets/dao.py 94.55% <100.00%> (+0.27%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 28, 2022
Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but we need to improve the test.

assert rv.status_code == 200

columns = db.session.query(TableColumn).filter_by(table_id=dataset.id).all()
assert len(columns) == 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an assert that the number of columns was not 3 before the update? (ie, in line ~790) Otherwise we don't know if the update actually did anything.

properties.pop("columns"),
commit=commit,
override_columns=bool(properties.get("override_columns")),
)

if "metrics" in properties:
cls.update_metrics(model, properties.pop("metrics"), commit=commit)
Copy link
Member

@eschutho eschutho Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for put /dataset, does override_columns literally mean just the columns or should we be overriding the metrics, too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from sqllab, we don't allow users to create metrics so if you look at the update_metrics function we end up just deleting all the rows since properties["metrics"] is always None from that context.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jul 30, 2022
@hughhhh hughhhh merged commit bc435e0 into apache:master Jul 30, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants