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

chore: Use datetime.timedelta for defining durations in config #16029

Merged
merged 2 commits into from
Aug 2, 2021

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Aug 2, 2021

SUMMARY

Encoding time durations (timeout, wait, etc.) as int seems un-Pythonic in world of typing. Furthermore:

  • It is not apparent whether a duration is in seconds, milliseconds, etc.
  • There are inconsistencies in how these config variables are defined, e.g. we have SQLLAB_VALIDATION_TIMEOUT and SQLLAB_ASYNC_TIME_LIMIT_SEC, where the later encodes the temporal units in the name.

Using datetime.timedelta remedies both these problems, i.e., timedelta(hours=1). This PR merely seeds this mindset (in the context of the configs) by replacing constructs like,

SCREENSHOT_LOAD_WAIT = 60

with

SCREENSHOT_LOAD_WAIT = int(timedelta(minutes=1).total_seconds())

whereas in the future it should simply be

SCREENSHOT_LOAD_WAIT: timedelta = timedelta(minutes=1)

where the code is updated to expect a datetime.timedelta object.

Note I raised pallets-eco/flask-caching#266 to see whether Flask-Caching would consider adding native support for using a datetime.timedelta object which would further simplify the code if we adopted this pattern.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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 Aug 2, 2021

Codecov Report

Merging #16029 (7ac7abd) into master (31d79ff) will decrease coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16029      +/-   ##
==========================================
- Coverage   77.01%   76.81%   -0.21%     
==========================================
  Files         990      990              
  Lines       52517    52547      +30     
  Branches     6642     6642              
==========================================
- Hits        40448    40362      -86     
- Misses      11845    11961     +116     
  Partials      224      224              
Flag Coverage Δ
hive ?
mysql 81.64% <100.00%> (+0.02%) ⬆️
postgres 81.64% <100.00%> (+<0.01%) ⬆️
presto ?
python 81.75% <100.00%> (-0.41%) ⬇️
sqlite 81.30% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
superset/config.py 91.24% <100.00%> (ø)
superset/db_engines/hive.py 0.00% <0.00%> (-82.15%) ⬇️
superset/db_engine_specs/hive.py 69.80% <0.00%> (-16.87%) ⬇️
superset/db_engine_specs/presto.py 83.47% <0.00%> (-6.91%) ⬇️
superset/views/database/mixins.py 81.03% <0.00%> (-1.73%) ⬇️
superset/connectors/sqla/models.py 88.00% <0.00%> (-1.70%) ⬇️
superset/db_engine_specs/base.py 87.98% <0.00%> (-0.39%) ⬇️
superset/models/core.py 89.61% <0.00%> (-0.26%) ⬇️
superset/utils/core.py 88.17% <0.00%> (-0.13%) ⬇️
superset/reports/api.py 91.30% <0.00%> (+3.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31d79ff...7ac7abd. Read the comment docs.

@john-bodley john-bodley force-pushed the john-bodley--datetime-timedelta branch from 8977465 to 7ac7abd Compare August 2, 2021 16:43
@john-bodley john-bodley changed the title chore: use datetime.timedelta for defining durations chore: Use datetime.timedelta for defining durations in config Aug 2, 2021
@john-bodley john-bodley force-pushed the john-bodley--datetime-timedelta branch from 7ac7abd to d18f167 Compare August 2, 2021 17:15
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.

This is great, thanks @john-bodley !

@john-bodley john-bodley merged commit 41e8190 into master Aug 2, 2021
@john-bodley john-bodley deleted the john-bodley--datetime-timedelta branch August 2, 2021 20:22
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
…e#16029)

* chore: use datetime.timedelta for defining durations

* Update config.py
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
…e#16029)

* chore: use datetime.timedelta for defining durations

* Update config.py
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…e#16029)

* chore: use datetime.timedelta for defining durations

* Update config.py
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
…e#16029)

* chore: use datetime.timedelta for defining durations

* Update config.py
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 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/M 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants