Commit Graph

20 Commits

Author SHA1 Message Date
Arik Fraimovich
2dff8b9a00
Black support for the Python codebase (#4297)
* Apply black formatting

* Add auto formatting when committing to master

* Update CONTRIBUTING.md re. Black & Prettier
2019-12-11 13:54:29 +02:00
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
f62d0e1300
Use lower cased names for groups: (#3221)
Otherwise sorting depends on the Postgres collation and causes tests
to fail on different envoirnments.
2018-12-26 17:16:13 +02:00
Udomomo
8257d9d037 Add permissions to the result of "manage.py groups list" command (#3007)
* Add permissions to the result of "groups list" command

* added permissions to test case

* removed setting for debug
2018-11-25 13:47:25 +02:00
GitSumito
bf6a09c5aa CLI sort (#3041) 2018-11-06 16:45:39 +01:00
GitSumito
2e6883c527 Add "Users" users are belong to into groups list (#2991) 2018-10-21 11:40:07 +03:00
GitSumito
45f4d46245 Add "Groups" users are belong to into users list (#2967) 2018-10-18 17:32:21 +03:00
GitSumito
a4b9c2da12 fixed https://github.com/getredash/redash/issues/2950 (#2951)
* fixed https://github.com/getredash/redash/issues/2950

* fixed test code

* Effective -> Active. thank you @kravets-levko
2018-10-15 15:57:51 +03:00
Jannis Leidel
b1f5d60460 Minor code smell cleanup. (#2820)
* Remove unused parse_db_url function.

* Fix tests to not show command line warnings anymore.

* Minor code smell cleanup.

Removing unneeded imports fixing PEP8 issues.
2018-09-16 09:43:44 +03:00
Arik Fraimovich
e4dba1ca8e Switch more strings to unicode. 2018-08-05 17:58:29 +03:00
Arik Fraimovich
f96a0f338d Use unicode strings. 2018-08-05 16:34:43 +03:00
Arik Fraimovich
3cadd6731c Fix: tests entering endless loop, due to bad input. 2017-10-01 14:26:04 +03:00
Allen Short
da31d983b7 Fix test_cli tests 2016-12-07 13:18:07 -06:00
Arik Fraimovich
74e6ef5c1d Fix users CLI tests 2016-12-07 15:54:08 +02:00
Arik Fraimovich
2b33963bee Add missing db.session.commit calls in CLI 2016-12-07 15:11:42 +02:00
Arik Fraimovich
a84c3e25f5 Move CLI logic into redash.cli and uses manager for tests.
Otherwise the Flask wasn't created and tests were failing.
2016-12-07 14:58:33 +02:00
Allen Short
520835dad0 Fix test_cli 2016-12-07 03:09:33 -06:00
Allen Short
80491ea4c2 Switch from flask_script to click, add CLI unit tests. 2016-12-06 15:14:44 -06:00