You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/06/17 04:58:31 UTC

[GitHub] [incubator-superset] john-bodley commented on a change in pull request #10079: fix: Ensuring /queries/ route accepts float or int

john-bodley commented on a change in pull request #10079:
URL: https://github.com/apache/incubator-superset/pull/10079#discussion_r441279107



##########
File path: superset/views/core.py
##########
@@ -2658,17 +2658,18 @@ def fetch_datasource_metadata(self) -> FlaskResponse:
         return json_success(json.dumps(datasource.data))
 
     @has_access_api
-    @expose("/queries/<last_updated_ms>")
-    def queries(self, last_updated_ms: str) -> FlaskResponse:
+    @expose("/queries/<float:last_updated_ms>")

Review comment:
       Note we require both routes as `float`  _only_ supports floating point  per [here](https://github.com/pallets/werkzeug/blob/237b35a63631fda0fe80eb51dccdfe8a2f50d304/src/werkzeug/routing.py#L1277) (and the associated regex) numbers.

##########
File path: setup.cfg
##########
@@ -45,7 +45,7 @@ combine_as_imports = true
 include_trailing_comma = true
 line_length = 88
 known_first_party = superset
-known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml
+known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dataclasses,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml

Review comment:
       The inclusion/exclusion of `dataclasses` depends on whether one is using Python 3.6 or Python 3.7+.

##########
File path: superset/views/core.py
##########
@@ -2658,17 +2658,18 @@ def fetch_datasource_metadata(self) -> FlaskResponse:
         return json_success(json.dumps(datasource.data))
 
     @has_access_api
-    @expose("/queries/<last_updated_ms>")
-    def queries(self, last_updated_ms: str) -> FlaskResponse:
+    @expose("/queries/<float:last_updated_ms>")
+    @expose("/queries/<int:last_updated_ms>")
+    def queries(self, last_updated_ms: Union[float, int]) -> FlaskResponse:
         """
         Get the updated queries.
 
-        :param last_updated_ms: unix time, milliseconds
+        :param last_updated_ms: Unix time (milliseconds)
         """
-        last_updated_ms_int = int(float(last_updated_ms)) if last_updated_ms else 0
-        return self.queries_exec(last_updated_ms_int)
 
-    def queries_exec(self, last_updated_ms: int) -> FlaskResponse:
+        return self.queries_exec(last_updated_ms)
+
+    def queries_exec(self, last_updated_ms: Union[float, int]) -> FlaskResponse:

Review comment:
       There's no need to round to the nearest millisecond since `datetime` object support microseconds.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org