Repository navigation
fix: Update dataset's last modified date from column/metric update - #33626
Vitor-Avila merged 6 commits into
Conversation
There was a problem hiding this comment.
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.
|
|
||
| data["result"]["metrics"].append(new_metric_data) | ||
|
|
||
| # Sleep to ensure that the changed_on is updated |
There was a problem hiding this comment.
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"):
...
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()There was a problem hiding this comment.
oh, TIL -- I can work on that
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
@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.
michael-s-molina
left a comment
There was a problem hiding this comment.
I left a non-blocking comment. Thanks for addressing the comments.
betodealmeida
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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()|
thanks for taking the time to review this @michael-s-molina and @betodealmeida 🙏 I really appreciate the valuable feedback. |
…pache#33626) (cherry picked from commit cacf1e0)
SUMMARY
The
last_modifiedvalue 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@transactiondecorator + the way we handle these updates:commitafter these changes -- ref.bulk_insert_mappingsfor the update which does not integrate well with SQLAlchemy's state management (and therefore does not trigger anafter_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
last_modifiedvalue for the dataset gets updated.ADDITIONAL INFORMATION