Commit Graph

59 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
Jannis Leidel
8456bbf762 Revert "Schema Viewer Drawer (#3291)" (#3585)
This reverts commit cb4d81d6ad.
2019-03-14 10:51:30 +02:00
Marina Samuel
cb4d81d6ad Schema Viewer Drawer (#3291)
* Process extra column metadata for a few sql-based data sources.

* Add Table and Column metadata tables.

* Periodically update table and column schema tables in a celery task.

* Fetching schema returns data from table and column metadata tables.

* Add tests for backend changes.

* Front-end shows extra table metadata and uses new schema response.

* Delete datasource schema data when deleting a data source.

* Process and store data source schema when a data source is first created or after a migration.

* Tables should have a unique name per datasource.

* Addressing review comments.

* Update migration file for mixins.

* Appease PEP8

* Upgrade migration file for rebase.

* Cascade delete.

* Adding org_id

* Remove redundant column and table prefixes.

* Non-existing tables and columns should be filtered out on the server side not client side.

* Fetching table samples should be optional and should happen in a separate task per table.

* Allow users to force a schema refresh.

* Use updated_at to help prune old schema metadata periodically.

* Using settings.SCHEMAS_REFRESH_QUEUE
2019-03-13 18:08:00 +01:00
Arik Fraimovich
e8120c5f79
Use None as "not scheduled" default value of a query (#3277)
* Use null as the default scheduled value.

* Don't serialize None to json, so we can use SQL is not null predicate.

* Fix warning about unicode in tests

* Handling empty query.schedule in UI (#3283)

* Add migration to convert empty schedules to null and drop the not null contraint.
2019-01-18 11:30:45 +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
YOSHIDA Katsuhiko
869841b2ac Preventing open redirection (#2906)
* Prevent open redirection attack

* Add redirection url after logging in test

* Sanitize url just before redirecting it

* Consider when next parameter is None
2018-10-17 21:55:58 +03:00
Arik Fraimovich
f96a0f338d Use unicode strings. 2018-08-05 16:34:43 +03:00
Arik Fraimovich
33b4c7c4c3 Move widget position logic migration to the backend and remove some unused code.
Closes #2218.
2018-02-01 14:40:40 +02:00
Arik Fraimovich
6f72d456d2 Remove unused code 2017-06-14 12:05:49 +03:00
Arik Fraimovich
83e6b6f50c Tests use the same session as the tested code, and we can't use the same
objects after the tested code calls commit() without disabling expire
on commit.

It seems like a safe thing in our case.
2017-03-06 13:49:29 +02:00
Arik Fraimovich
463da02be1 remove group_hack method (unused) 2016-12-07 12:01:44 +02:00
Arik Fraimovich
6b0e45441c Update QuerySnippets code to SQLA 2016-12-07 12:01:03 +02:00
Arik Fraimovich
c0f48909a7 Fix destinations handlers code 2016-12-07 02:13:52 -06:00
Arik Fraimovich
802b812932 Fix query results tests 2016-12-07 02:13:20 -06:00
Arik Fraimovich
f4c76527ee Fix refresh queries tests 2016-12-07 02:13:20 -06:00
Allen Short
bb755b5c25 test_models fixes 2016-12-07 02:13:20 -06:00
Allen Short
d1fcb43562 test_alerts passes 2016-12-07 02:13:20 -06:00
Arik Fraimovich
8680ebe96f Change Dashboard factory to generate non drafts 2016-12-07 02:13:20 -06:00
Allen Short
c2378d837a test_handlers passes 2016-12-07 02:13:20 -06:00
Arik Fraimovich
2a525210e4 Start fixing visualizations tests 2016-12-07 02:13:20 -06:00
Allen Short
f00d77dec4 auth tests wip 2016-12-07 02:13:20 -06:00
Allen Short
ea166665d3 test_models passes 2016-12-07 02:13:20 -06:00
Allen Short
24217d969e schema for sqlalchemy, basic test support 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
6c5dd09a78 Add change tracking and fix tests 2016-10-26 16:09:55 +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
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
2d2fb69b7b Add API to delete alerts (#731). 2016-06-14 11:21:05 +03:00
Arik Fraimovich
4cbc79a7aa Use default user for alert_subscription factory 2016-06-14 11:04:41 +03:00
Arik Fraimovich
434615a1be Merge remote-tracking branch 'origin/master' into flexible_notifications 2016-06-02 10:21:52 +03:00
Arik Fraimovich
9538ee7c31 Feature: API to pause a data source 2016-05-30 18:30:05 +03:00
Arik Fraimovich
e069374232 Merge w/ latest master 2016-05-07 17:49:49 +03:00
Waldemar Hummer
e415189017 add test case for embeds with parameters; minor fix in embeds.py 2016-05-05 11:15:49 +10:00
Alex DeBrie
1c04f3cc29 Fix broken tests 2016-03-24 13:55:46 +00:00
Alex DeBrie
a3c0917d85 Fix AlertSubscription unsubscribe permissions and broken tests 2016-03-23 20:49:20 +00:00
Alex DeBrie
a43761da39 Require destination_id in POSTs that create a subscription 2016-03-23 20:47:50 +00:00
Arik Fraimovich
6bc3970ad5 Make sure user has access to data source when loading query result 2016-03-09 15:15:03 +02:00
Arik Fraimovich
52ad1f1ba1 Public dasboards feature. 2016-03-09 13:38:02 +02:00
Arik Fraimovich
ed99b8452c Encapsulate data source/query runner configuration in an object.
This is a step towards adding more complex logic in configuration
handling, like encryption of secrets.
2016-02-23 15:02:49 +02:00
Arik Fraimovich
7c6b95e71d Change multi-org implementation:
To avoid complications with how Google Auth works, when enabling organization
multi-tenancy on a single instance, each organization becomes a "sub folder"
instead of a sub-domain.
2016-01-04 00:03:49 +02:00
Arik Fraimovich
f7b57fa580 Feature: new permissions system
This is one huge change for the permissions system and related:

* (Backward incompatible:) Remove the table based permissions in favour of the new model.
* Manage permission to view or query datasources based on groups.
* Add the concept of Organization. It's irrelevant for most deployments, but allows for
  multi-tenant support in re:dash.
* Replace ActivityLog with Event based rows (old data in activity_log table is retained).
* Enforce permissions on the server-side. There were some permissions that were only enforced
  on the client side. This is no more. All permissions are enforced by the server.
* Added new permission: 'super-admin' to access the status and Flask-Admin interface.
* Make sure that html is never cached by the browser - this is to make sure that the browser
  will always ask for the new Javascript/CSS resources (if such are available).
2015-12-31 10:43:33 +02:00
Arik Fraimovich
a60b1686da Fix: when the server has non UTC timezone, timestamps were wrong 2015-06-03 07:58:28 +03:00
Arik Fraimovich
d3d305a843 Make sure data sources have unique names in tests 2015-04-18 22:46:42 +03:00
Arik Fraimovich
e3cc3ef9a4 Move schema fetching to DataSource + tests 2015-04-02 11:25:42 +03:00
Arik Fraimovich
faad6b656b Change query ttl field to be a string and named schedule.
This to allow other types of scheduling than just repeat every X seconds.
The first supported option will be: repeat every day at hour X.
2015-04-01 11:23:26 +03:00
Arik Fraimovich
1afd2ab388 Refactoring of @christophervalles work on query delete feature:
- Change delete into archive.
- Safely remove widgets.
- Make sure archived queries don't get scheduled, or show up in search.
- If direct link to query used, show notification.
- Tests.
- Some more.
2015-01-25 16:17:52 +02:00
Arik Fraimovich
dad9eb21a0 Create user groups in test setup. 2014-05-13 18:29:59 +03:00
Christopher Valles
81d027611f Remove is_admin flag 2014-05-09 18:12:34 +01:00
Christopher Valles
1c095bcd99 Fix tests 2014-05-09 12:43:29 +01:00