-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
# pylint: disable=C,R,W | ||
"""Views used by the SqlAlchemy connector""" | ||
import logging | ||
import re | ||
|
||
from flask import flash, Markup, redirect | ||
from flask_appbuilder import CompactCRUDMixin, expose | ||
|
@@ -27,6 +28,7 @@ | |
from flask_babel import gettext as __ | ||
from flask_babel import lazy_gettext as _ | ||
from wtforms.ext.sqlalchemy.fields import QuerySelectField | ||
from wtforms.validators import Regexp | ||
|
||
from superset import appbuilder, db, security_manager | ||
from superset.connectors.base.views import DatasourceModelView | ||
|
@@ -99,12 +101,17 @@ class TableColumnInlineView(CompactCRUDMixin, SupersetModelView): # noqa | |
), | ||
"python_date_format": utils.markdown( | ||
Markup( | ||
"The pattern of timestamp format, use " | ||
"The pattern of timestamp format. For strings use " | ||
'<a href="https://docs.python.org/2/library/' | ||
'datetime.html#strftime-strptime-behavior">' | ||
"python datetime string pattern</a> " | ||
"expression. If time is stored in epoch " | ||
"format, put `epoch_s` or `epoch_ms`." | ||
"python datetime string pattern</a> expression which needs to " | ||
'adhere to the <a href="https://en.wikipedia.org/wiki/ISO_8601">' | ||
"ISO 8601</a> standard to ensure that the lexicographical ordering " | ||
"coincides with the chronological ordering. If the timestamp " | ||
"format does not adhere to the ISO 8601 standard you will need to " | ||
"define an expression and type for transforming the string into a " | ||
"date or timestamp. Note currently time zones are not supported. " | ||
"If time is stored in epoch format, put `epoch_s` or `epoch_ms`." | ||
), | ||
True, | ||
), | ||
|
@@ -121,6 +128,24 @@ class TableColumnInlineView(CompactCRUDMixin, SupersetModelView): # noqa | |
"python_date_format": _("Datetime Format"), | ||
"type": _("Type"), | ||
} | ||
validators_columns = { | ||
"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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
re.compile( | ||
r""" | ||
^( | ||
epoch_s|epoch_ms| | ||
(?P<date>%Y(-%m(-%d)?)?)([\sT](?P<time>%H(:%M(:%S(\.%f)?)?)?))? | ||
)$ | ||
""", | ||
re.VERBOSE, | ||
), | ||
message=_("Invalid date/timestamp format"), | ||
) | ||
] | ||
} | ||
|
||
add_form_extra_fields = { | ||
"table": QuerySelectField( | ||
|
@@ -303,7 +328,6 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa | |
"template_params": _("Template parameters"), | ||
"modified": _("Modified"), | ||
} | ||
|
||
edit_form_extra_fields = { | ||
"database": QuerySelectField( | ||
"Database", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.