Commit Graph

23 Commits

Author SHA1 Message Date
Nicolas Le Manchet
246eca1121 Migrate the application to Python 3 (#4251)
* Make core app compatible with Python 3

No backward compatibility with Python 2.7 is kept.
This commit mostly contains changes made with 2to3 and manual
tweaking when necessary.

* Use Python 3.7 as base docker image

Since it is not possible to change redash/base:debian to Python 3
without breaking future relases, its Dockerfile is temporarly
copied here.

* Upgrade some requirements to newest versions

Some of the older versions were not compatible with Python 3.

* Migrate tests to Python 3

* Build frontend on Python 3

* Make the HMAC sign function compatible with Python 3

In Python 3, HMAC only works with bytes so the strings and the
float used in the sign function need to be encoded.
Hopefully this is still backward compatible with already generated
signatures.

* Use assertCountEqual instead of assertItemsEqual

The latter is not available in Python 3.
See https://bugs.python.org/issue17866

* Remove redundant encoding header for Python 3 modules

* Remove redundant string encoding in CLI

* Rename list() functions in CLI

These functions shadow the builtin list function which is
problematic since 2to3 adds a fair amount of calls to the builtin
list when it finds dict.keys() and dict.values().

Only the Python function is renamed, from the perspective of the
CLI nothing changes.

* Replace usage of Exception.message in CLI

`message` is not available anymore, instead use the string
representation of the exception.

* Adapt test handlers to Python 3

* Fix test that relied on dict ordering

* Make sure test results are always uploaded (#4215)

* Support encoding memoryview to JSON

psycopg2 returns `buffer` objects in Python 2.7 and `memoryview`
in Python 3. See #3156

* Fix test relying on object address ordering

* Decode bytes returned from Redis

* Stop using e.message for most exceptions

Exception.message is not available in Python 3 anymore, except
for some exceptions defined by third-party libraries.

* Fix writing XLSX files in Python 3

The buffer for the file should be made of bytes and the actual
content written to it strings.

Note: I do not know why the diff is so large as it's only a two
lines change. Probably a white space or file encoding issue.

* Fix test by comparing strings to strings

* Fix another exception message unavailable in Python 3

* Fix export to CSV in Python 3

The UnicodeWriter is not used anymore. In Python 3, the interface
provided by the CSV module only deals with strings, in and out.
The encoding of the output is left to the user, in our case
it is given to Flask via `make_response`.

* (Python 3) Use Redis' decode_responses=True option (#4232)

* Fix test_outdated_queries_works_scheduled_queries_tracker (use utcnow)

* Make sure Redis connection uses decoded_responses option

* Remove unused imports.

* Use Redis' decode_responses option

* Remove cases of explicit Redis decoding

* Rename helper function and make sure it doesn't apply twice.

* Don't add decode_responses to Celery Redis connection URL

* Fix displaying error while connecting to SQLite

The exception message is always a string in Python 3, so no
need to try to decode things.

* Fix another missing exception message

* Handle JSON encoding for datasources returning bytes

SimpleJSON assumes the bytes it receives contain text data, so it
tries to UTF-8 encode them. It is sometimes not true, for instance
the SQLite datasource returns bytes for BLOB types, which typically
do not contain text but truly binary data.

This commit disables SimpleJSON auto encoding of bytes to str and
instead uses the same method as for memoryviews: generating a
hex representation of the data.

* Fix Python 3 compatibility with RQ

* Revert some changes 2to3 tends to do (#4261)

- Revert some changes 2to3 tends to do when it errs on the side of caution regarding dict view objects.

- Also fixed some naming issues with one character variables in list comprehensions.

- Fix Flask warning.

* Upgrade dependencies

* Remove useless `iter` added by 2to3

* Fix get_next_path tests (#4280)

* Removed setting SERVER_NAME in tests setup to avoid a warning.

* Change get_next_path to not return empty string in case of a domain only value.

* Fix redirect tests:

Since version 0.15 of Werkzeug it uses full path for fixing the location header instead of the root path.

* Remove explicit dependency for Werkzeug

* Switched pytz and certifi to unbinded versions.

* Switch to new library for getting country from IP

`python-geoip-geolite2` is not compatible with Python 3, instead
use `maxminddb-geolite2` which is very similar as it includes
the geolite2 database in the package .

* Python 3 RQ modifications (#4281)

* show current worker job (alongside with minor cosmetic column tweaks)

* avoid loading entire job data for queued jobs

* track general RQ queues (default, periodic and schemas)

* get all active RQ queues

* call get_celery_queues in another place

* merge dicts the Python 3 way

* extend the result_ttl of refresh_queries to 600 seconds to allow it to continue running periodically even after longer executions

* Remove legacy Python flake8 tests
2019-10-24 12:42:13 +03:00
YOSHIDA Katsuhiko
8e38dcd244 Support regenerating Query API Key (#3764)
* Add regenerate function of query's API Key

* Add regenerate API Key button

* Add regenerate Query API Key tests

* Fix too long line

* Replace  with this

* Return a simple version query

* Update only API Key

* Update API Key via query
2019-06-12 13:09:21 +03:00
Omer Lachish
c93a905c1d
Fix Ability to save with Multiple Dropdown Parameters (#3717)
* support multiple associations of the same query-based dropdown parameter

* include several query-based parameters in association tests
2019-04-28 14:25:26 +03:00
Jannis Leidel
712fc63f93 Use flask-talisman for handling backend response headers (#3404)
* Normalize Flask initialization API use.

* Use Flask-Talisman.

* Enable HSTS when HTTPS is enforced.

* More details about how CSP is formatted and write CSP directives as a string.

* Use CSP frame-ancestors directive and not X-Frame-Options for embedable endpoints.

* Add link to flask-talisman docs.

* set remember_token cookie to be HTTP-Only and Secure

* Reorganize secret key configuration to be forward thinking and backward compatible.
2019-03-27 17:24:15 +02:00
Omer Lachish
c47dd05095
Nest query ACL to dropdowns (#3544)
* change API to /api/queries/:id/dropdowns/:dropdown_id

* extract  property

* split to 2 different dropdown endpoints and implement the second

* make access control optional for dropdowns (assuming it is verified at a
different level)

* add test cases for /api/queries/:id/dropdowns/:id

* use new /dropdowns endpoint in frontend

* require access to dropdown queries when creating or updating parent
queries

* rename Query resource dropdown endpoints

* check access to dropdown query associations in one fugly query

* move ParameterizedQuery to models folder

* add dropdown association tests to query creation

* move group by query ids query into models.Query

* use bound parameters for groups query

* format groups query

* use new associatedDropdowns endpoint in dashboards

* pass down parameter and let it return dropdown options. Go Levko!

* change API to /api/queries/:id/dropdowns/:dropdown_id

* split to 2 different dropdown endpoints and implement the second

* use new /dropdowns endpoint in frontend

* pass down parameter and let it return dropdown options. Go Levko!

* fix bad rebase

* add comment to clarify the purpose of checking the queryId
2019-03-20 09:16:10 +02:00
Jannis Leidel
69e34f048a Add archived queries section to queries list. (#2888)
* Add archived queries section to queries list.

* Refactor route building for list based controllers.

This also fixes the dashboard empty state page.
2019-02-03 14:35:25 +02:00
Marina Samuel
cdd2259d08 Closes #2396: Add finer-grained scheduling. (#2426)
* Closes #187: Add finer-grained scheduling - backend.

* Closes #2396 - Add finer-grained scheduling - frontend.

* Fix linting issues

* Rename ScheduleDialgo to .jsx
2019-01-06 10:59:50 +02:00
Jannis Leidel
2af926703a
Implement server side sorting and new search.
- Redirect the old search API handler.
- Sort by specific database columns or relationships.
- Allow showing “my” queries per tag as well.
2018-07-18 22:55:19 +02:00
Arik Fraimovich
2eefdc1da3 Updated queries screen (& unified API). 2018-06-26 21:50:16 +03:00
Arik Fraimovich
aa756b2be6 Almost complete implementation of favorties backend 2018-06-06 14:41:13 +03:00
Arik Fraimovich
64f70cfbe8 Query favorites: API stub. 2018-06-06 14:37:52 +03:00
ariarijp
f5d4ca85d8 Upgrade sqlparse to 0.2.4
Add test case for /api/queries/format
2018-02-23 01:24:34 +09:00
Arik Fraimovich
4e4a3e13ab Fix #1824: allow only user API key to be used with query refresh API. 2017-11-01 15:05:55 +02:00
Arik Fraimovich
2bc3885977 Fix: require full access to the data source to fork a query.
Ref #1825.
2017-11-01 14:46:29 +02:00
Arik Fraimovich
03b2a416c8 Fix queries update handler 2016-12-07 02:13:52 -06:00
Arik Fraimovich
c5548e9375 Fix query handlers test 2016-12-07 02:13:20 -06:00
Allen Short
65a6385380 Make draft status for queries and dashboards toggleable. 2016-11-02 12:31:33 -05:00
Arik Fraimovich
df17759ab4 Fix tests 2016-10-26 11:47:40 +03:00
Arik Fraimovich
edea6f3a05 WIP:
- Move version/change tracking logic to mixins (the change mixin is still WIP).
- Tests for queries update API.
2016-10-24 16:58:30 +03:00
Waldemar Hummer
e0672f4c4d add optimistic locking for dashboard editing 2016-10-24 12:33:29 +03:00
Waldemar Hummer
903ba0c1e0 add backend API and tests for managing access permissions. 2016-10-24 12:33:29 +03:00
Arik Fraimovich
5096e4ed79 Change: paginate query page & add explicit urls.
- Paginate the queries API result.
- Split the API to /api/queries (all queries) and /api/queries/my which returns
  a user's queries (or drafts).
- In the interface have explicit URLs for all queries (/queries), my queries (/queries/my)
  and drafts (/queries/drafts).
2016-10-05 14:14:26 +03:00
Arik Fraimovich
c12b059d10 Add API to trigger query refresh and support for parameters. 2016-02-22 10:40:46 +02:00