Skip to content

fix: Update dataset's last modified date from column/metric update - #33626

Merged
Vitor-Avila merged 6 commits into
masterfrom
fix/update-dataset-last-modified-for-column-metrics-change
Jun 3, 2025
Merged

Vitor-Avila merged 6 commits into
masterfrom
fix/update-dataset-last-modified-for-column-metrics-change

Conversation

@Vitor-Avila

@Vitor-Avila Vitor-Avila commented May 30, 2025 •

Copy link
Copy Markdown
Contributor

SUMMARY

The last_modified value for datasets was not getting updated in case only metric(s) and/or column(s) changed. I suspect the issue started with the introduction of the @transaction decorator + the way we handle these updates:

  • Before SIP-99B, we would commit after these changes -- ref.
  • We're currently using bulk_insert_mappings for the update which does not integrate well with SQLAlchemy's state management (and therefore does not trigger an after_update) -- ref.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before

Screen.Recording.2025-05-30.at.1.06.52.AM.mov

After

Screen.Recording.2025-05-30.at.12.57.09.AM.mov

TESTING INSTRUCTIONS

  1. Apply a label to a column, and confirm the last_modified value for the dataset gets updated.

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

@dosubot dosubot Bot added the data:dataset Related to dataset configurations label May 30, 2025

@korbit-ai korbit-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've completed my review and didn't find any issues.

Files scanned ​
File Path Reviewed
superset/daos/dataset.py ✅
superset/connectors/sqla/models.py ✅

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment thread superset/daos/dataset.py Resolved
@pull-request-size pull-request-size Bot added size/L and removed size/S labels Jun 2, 2025
Comment thread superset/daos/dataset.py Resolved

data["result"]["metrics"].append(new_metric_data)

# Sleep to ensure that the changed_on is updated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional: You can use freezegun to control time and make tests more accurate and efficient.

from freezegun import freeze_time

with freeze_time("2021-01-01T00:00:00Z"):
   ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@michael-s-molina thank you 🙏 I used that in another test, but here I intentionally want to confirm that the new value for changed_on is more recent than the old one, so this should be sufficient. I wanted to avoid mocking it to ensure the logic is properly applied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can do something like:

@freeze_time("2023-10-01")
def test_advance_time():
    # Check the initial frozen time
    assert datetime.now() == datetime(2023, 10, 1)
    
    # Advance time by one day
    freeze_time().tick()
    
    # Now it should reflect the new time
    assert datetime.now() == datetime(2023, 10, 2)

This will make your test run instantly instead of taking 3 seconds to execute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh yeah, we should avoid calling sleep() on tests. With freezegun you can do:

 with freeze_time(initial_datetime) as frozen:
    do_something()
    frozen.tick(delta=timedelta(seconds=3))
    do_something_else()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, TIL -- I can work on that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, this is done now! 🙌 I'll work on a follow up to remove time.sleep() from other places I found in the code. I'll probably combine that with a deprecation of datetime.now()

sa.event.listen(SqlaTable, "before_update", SqlaTable.before_update)
sa.event.listen(SqlaTable, "after_insert", SqlaTable.after_insert)
sa.event.listen(SqlaTable, "after_delete", SqlaTable.after_delete)
sa.event.listen(SqlMetric, "after_update", SqlaTable.update_column)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Vitor-Avila The previous event-based implementation was triggered for changes from any source. This means that any time SqlMetric or TableColumn was updated, from any part of the code, the timestamp was updated. Did we check to see if these models are updated outside the DAO?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@michael-s-molina the only other place I found that was modifying these is via import flows, which I manually tested and confirmed it is updating the changed_on as well, so I believe we're good. Other than that I found some migrations.

If we find other places in the future, happy to do a follow up tho.

Comment thread superset/daos/dataset.py Resolved

@michael-s-molina michael-s-molina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left a non-blocking comment. Thanks for addressing the comments.

@betodealmeida betodealmeida left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's remove the sleep() from the tests, it's a slippery slope — people will start copying the pattern and make the tests take even more time.


data["result"]["metrics"].append(new_metric_data)

# Sleep to ensure that the changed_on is updated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh yeah, we should avoid calling sleep() on tests. With freezegun you can do:

 with freeze_time(initial_datetime) as frozen:
    do_something()
    frozen.tick(delta=timedelta(seconds=3))
    do_something_else()

@Vitor-Avila
Vitor-Avila requested a review from betodealmeida June 3, 2025 14:44

@betodealmeida betodealmeida left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@Vitor-Avila

Copy link
Copy Markdown
Contributor Author

thanks for taking the time to review this @michael-s-molina and @betodealmeida 🙏 I really appreciate the valuable feedback.

@Vitor-Avila
Vitor-Avila merged commit cacf1e0 into master Jun 3, 2025
@Vitor-Avila
Vitor-Avila deleted the fix/update-dataset-last-modified-for-column-metrics-change branch June 3, 2025 15:20
LevisNgigi pushed a commit to LevisNgigi/superset that referenced this pull request Jun 18, 2025
alexandrusoare pushed a commit to alexandrusoare/superset that referenced this pull request Jun 19, 2025
@michael-s-molina michael-s-molina added the v5.0 Label added by the release manager to track PRs to be included in the 5.0 branch label Jul 30, 2025
michael-s-molina pushed a commit that referenced this pull request Jul 30, 2025
michael-s-molina pushed a commit that referenced this pull request Jul 30, 2025
@github-actions github-actions Bot added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 6.0.0 First shipped in 6.0.0 labels Dec 18, 2025
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
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 data:dataset Related to dataset configurations size/L v5.0 Label added by the release manager to track PRs to be included in the 5.0 branch 🚢 6.0.0 First shipped in 6.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants