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

[SIP-15A] Enforcing ISO 8601 date/timestamp formats #7702

Merged
merged 1 commit into from
Oct 17, 2019

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jun 13, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Per SIP-15A this PR helps to ensure that the when specifying a string like temporal column the date/timestamp strftime format adheres to the ISO 8601 format. The TL;DR is if we're going to filter (and thus order) dates we need to use a representation where the lexicographical order coincides with the chronological order (see the ISO 8601 section in the SIP for details).

This PR updates the CRUD and inline datasource editor (and adds validation where appropriate). Regrettable it seems in FAB we can't couple multiple fields, i.e., if the "Is temporal" field is unchecked then disable the "Datetime Format" field (@dpgaspar may know of how to do this). Additionally the messaging seems to be omitted if the form field is invalid (I was able to make this work for the default "Detail" tab (per here) but not for the "Columns" tab.

I originally when down the rabbit hole of replacing the strftime formatting to using the more restrictive ISO 8601 constructs, i.e., YYYY-MM-DD hh:mm:ss.SSSSSS including providing a migration. I finally opted against this as the datetime object doesn't support formatting using the ISO 8601 tokens (packages like arrow and pendulumn do however) and it seems like we heavily depend of the strftime format for transforming Pandas dataframe.

Note in the future I think there may be merit in trying to migrate to using the ISO 8601 tokens as this seems more standard and a time format which a number of engines support.

Finally there is no migration or corrective actions for currently ill-defined formats. This PR simply ensures that new formats are correct moving forward.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen Shot 2019-10-16 at 9 22 16 AM

Screen Shot 2019-10-16 at 9 34 56 AM

TEST PLAN

CI and tested the regex validator.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @betodealmeida @michellethomas @mistercrunch @villebro

@codecov-io
Copy link

codecov-io commented Jun 13, 2019

Codecov Report

Merging #7702 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7702      +/-   ##
==========================================
+ Coverage   67.65%   67.65%   +<.01%     
==========================================
  Files         448      448              
  Lines       22498    22501       +3     
  Branches     2364     2364              
==========================================
+ Hits        15220    15223       +3     
  Misses       7140     7140              
  Partials      138      138
Impacted Files Coverage Δ
...uperset/assets/src/datasource/DatasourceEditor.jsx 62.09% <ø> (ø) ⬆️
superset/connectors/sqla/models.py 84.96% <ø> (ø) ⬆️
superset/connectors/sqla/views.py 67.79% <100%> (+0.84%) ⬆️

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 c422b49...c30af86. Read the comment docs.

String or Integer(epoch) type`)}
{t(' expression which needs to adhere to the ')}
<a href="https://en.wikipedia.org/wiki/ISO_8601">
{t('ISO 8601')}
Copy link
Member

Choose a reason for hiding this comment

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

none of this i18n stuff really works, but since it was bad before I don't see it worthwhile to fix now (or how best to fix it while still embedding links). Maybe we should add a TODO here to do the i18n the right way in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

superset/connectors/sqla/views.py Outdated Show resolved Hide resolved
@@ -99,14 +99,23 @@ function ColumnCollectionTable({
label={t('Datetime Format')}
descr={
<div>
{t('The pattern of the timestamp format, use ')}
{t('The pattern of timestamp format. For string use ')}
Copy link
Member

Choose a reason for hiding this comment

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

nit: For strings

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@john-bodley john-bodley force-pushed the john-bodley--iso-8601 branch 4 times, most recently from fe4a0f0 to 2e53eb1 Compare June 14, 2019 00:10
@stale
Copy link

stale bot commented Aug 20, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label Aug 20, 2019
@stale stale bot closed this Aug 27, 2019
@john-bodley john-bodley reopened this Oct 16, 2019
@stale stale bot removed the inactive Inactive for >= 30 days label Oct 16, 2019
@john-bodley john-bodley force-pushed the john-bodley--iso-8601 branch 2 times, most recently from c30af86 to 62d6a1b Compare October 16, 2019 16:31
@john-bodley john-bodley changed the title [sqla] Enforcing ISO 8601 date/timestamp formats [SIP-15A] Enforcing ISO 8601 date/timestamp formats Oct 16, 2019
"python_date_format": [
# Restrict viable values to epoch_s, epoch_ms, or a strftime format
# which adhere's to the ISO 8601 format (without time zone).
Regexp(
Copy link
Member Author

Choose a reason for hiding this comment

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

@dpgaspar this FAB validator works but it doesn't seem to show the message. I've successfully used validators in Superset on other PRs and I was wondering whether there's a FAB issue displaying messages when the form field isn't on the primary tab.

@john-bodley john-bodley merged commit a199901 into apache:master Oct 17, 2019
@john-bodley john-bodley deleted the john-bodley--iso-8601 branch October 17, 2019 17:06
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.35.0 labels Feb 19, 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 🚢 0.35.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants