Commit Graph

71 Commits

Author SHA1 Message Date
Omer Lachish
a9cb87d4b3
refresh_queries shouldn't break because of a single query having a bad schedule object (#4163)
* move filtering of invalid schedules to the query

* simplify retrieved_at assignment and wrap in a try/except block to avoid one query blowing up the rest

* refactor refresh_queries to use simpler functions with a single responsibility and add try/except blocks to avoid one query blowing up the rest

* avoid blowing up when job locks point to expired Job objects. Enqueue them again instead

* there's no need to check for the existence of interval - all schedules have intervals

* disable faulty schedules

* reduce FP style in refresh_queries

* report refresh_queries errors to Sentry (if it is configured)

* avoid using exists+fetch and use exceptions instead
2020-03-01 11:02:46 +02:00
Arik Fraimovich
30bc1e2ff6
Refine permissions usage in Redash to allow for guest users (#4492)
* Allow executing query with either view_query or execute_query permissions.

* Render AuthHeader according to permissions.

* Don't return dashboards where you only have access to textbox widget.

Closes #4099.
2019-12-30 10:07:20 +02:00
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
Arik Fraimovich
204447a9f5
Add interface to abstract query result persistence (#4147)
* Add interface to implement custom persistence for QueryResult data

Co-authored-by: Omer Lachish <omer@rauchy.net>

* Deserialize query results data in the model

* Change order of mixins.

* Make DBPersistence.data setter in sycn with getter + tests
2019-10-10 10:39:55 +03:00
Guy Cohen
21a27ee0b1 Fix OverflowError on celery worker (#3899) 2019-06-16 11:34:29 +03: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
Arik Fraimovich
08953cc919
Redis based implementation of user active_at timestamp update (#3256)
* Switch to simpler implementation
* Fix active_at update code
* Fix sync test
2019-01-08 14:03:49 +02:00
Jannis Leidel
44dff83046 Add "Active at" column to user list. (#3026)
* add last_active_at to users page

* Use our JSON encoder as the SQLAlchemy JSON serializer.

* Fixed some inconsistencies in the user query class methods.

* Minor cosmetic fixes.

* Add some make tasks for easier development.

* Add user detail sync system based on Redis backend.

There is a periodic Celery task that updates a new “details” JSONB column in the “user” table with the data from Redis.

Currently this is only used for tracking the date of last activity of a user but can be extended with other user information later.

Updates a few dependencies.

* Normalize a few Flask extension API names.

* Reduce implementation complexity of JSONEncoder.

* Use request_started signal to make sure we have a request context.

Otherwise loading the user based on the request won’t work.

* Fix test that checks if disabled users can login.

This correctly uses a URL path that includes the current organization and checks for the error message.

The previous test seems to have been a red herring.

* Minor cosmetic fixes.

* Remove needs_sync in favor of just deleting things.

* Misc review fixes.

* Ignore line length.

* Split redash.models import several modules.

* Move walrus UTC DateTimeField into redash.models.types.

* Restore distinctly loading dashboards.

* Simplify default values for user details.

* Define __repr__ methods generically.

* Consistently have underscore methods at the top of model methods.

* Fix tests.

* Split redash.models import several modules.

* Update to latest walrus and redis-py.

* Update kombu to 4.2.2 for redis-py 3.x compatibility.

* Remove redis-cli container after running Make task.

* Move buffer condition after datetime/time conditions.

* Update walrus to 0.7.1.

* Refactor some query APIs.

This uses the flask-sqlalchemy helpers consistently and makes more use of mixins.

* Post rebase fixes.

* Use correct kombu version

* Fix migration down revision
2019-01-07 10:30:42 +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
Omer Lachish
c66f63d7a5 Prevent Query's updated_at from changing when it is linked to new query results (#3082)
* avoid Query's updated_at from changing when it is linked to new query results

* move comment to previous line

* move QueryResult tests to their own module

* add test which verifies that updated_at is not changed on query data
updates

* tests were false positives - they compared HH:MM:SS, but that never
changed because the original time was 1 week behind.

* remove redundant constructor

* remove hack and use a proper event to prevent updated_at from changing

* use self.assertEqual instead of assert
2018-11-20 12:22:15 +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
7553eef024 Remove dashboards recents tests 2018-05-14 11:02:25 +03:00
Arik Fraimovich
c054731794 Change: close metadata database connection early in the execute query
Celery task. This to prevent the task holding an idle connection for
a long period of time, while waiting for the query to finish.
2018-03-08 11:06:15 +02: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
fbd3b92ba0 Fix: delete data source doesn't work when query results referenced by queries. 2017-06-02 18:11:34 +03:00
Arik Fraimovich
beb29c66c2 Scheduled queries improvements:
* Schedule queries with parameters using the default value.
* Keep track of last execution (including failed ones) for scheduling purposes.
2017-05-18 15:10:19 +03:00
Arik Fraimovich
903463972b Fix: handle the case when a scheduled query wasn't run before 2017-04-02 15:20:45 +03:00
Allen Short
2407b115e4 Exponential backoff for failing queries 2017-02-22 10:29:08 -06:00
Allen Short
ca3e125da8 Refactor outdated_queries/refresh_queries tests 2017-02-22 10:28:35 -06:00
Arik Fraimovich
ad18128794 Fix test 2017-02-02 10:39:21 +02:00
Arik Fraimovich
febe908e65 Revise drafts flow for queries:
* Draft queries are now called "Unpublished" -- felt like it better convey the feature.
* Unpublished queries won't be shown in "All Queries" for non owners, but will appear in
  search.
* You can't add unpublished queries to dashboards or alerts.
2017-01-25 16:55:39 +02:00
Arik Fraimovich
c900e83bd9 Fix #1499: queries search should be case insensitive 2017-01-02 11:28:23 +02:00
Arik Fraimovich
d631171e81 Fix Query.recent tests 2016-12-11 15:54:13 +02:00
Arik Fraimovich
1978e07748 Use group ids instead of groups in Queries.search/recent 2016-12-11 15:11:30 +02:00
Arik Fraimovich
1d18109964 Fix tests that used Query.all_queries 2016-12-08 16:07:25 +02:00
Allen Short
4945d0bec7 fix cleanup_query_results task 2016-12-07 19:59:48 -06:00
Arik Fraimovich
fb75626458 Create default visualization using a method instead of signal 2016-12-07 12:02:57 +02:00
Arik Fraimovich
045e880f25 Add dedicated delete method to widgets instead of using an event 2016-12-07 12:02:46 +02:00
Arik Fraimovich
0c974bd48b Update User.find_by_email to SQLA 2016-12-07 12:02:31 +02:00
Arik Fraimovich
4459c464ca use Query#query_text instead of Query#query 2016-12-07 02:13:20 -06:00
Allen Short
bb755b5c25 test_models fixes 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
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
da4db94cf8 Close #930: remove alerts for archived queries 2016-06-14 11:09:35 +03:00
Kumar Vora
8900d02c95 fixing test 2016-05-20 14:35:49 -05:00
Kumar Vora
c1c2db4a73 use user.org instead of passing org as a separate argument 2016-05-20 14:28:08 -05:00
Ama Asare
ad85b9a62c Ama/Kumar: Configure authorization for SAML 2016-05-17 14:01:18 -05:00
Arik Fraimovich
d9cc063be2 Fix: make sure we return dashboards only for current org 2016-05-04 16:32:49 +03:00
Arik Fraimovich
5bd133ca50 Add additional tests 2016-04-20 18:30:31 +03:00
Arik Fraimovich
3ce07782ad Fix #986: search might return duplicate queries 2016-04-20 17:54:20 +03:00
Seva Gavrilov
c98cdef8f2 Fixed dashboard restrictions and added tests. 2016-03-29 13:27:35 -03:00
Jeff Widman
1aad95986b Add spaces around arithmetic operators per PEP 8 2016-02-29 12:34:50 -08:00
yohei.naruse
0afca7321a #801 fix test case.
schedule = "{:02d}:00".format(now.hour - 3) maybe be negative value when now.hour < 3.
I've fixed it.
2016-02-16 13:16:31 +09: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
9b47f0d08a Fix: test shouldn't depend on currnet time 2015-10-16 23:10:50 +03:00
Arik Fraimovich
3d859ec5f3 Feature: alerts for query results.
This is basic implementation for alerts feature, where you can
define a simple rule on the last query result to send an alert.

As part of the implementation added Flask-Mail to the project,
to send emails. Should be useful to make re:dash more "self aware"
(notify users about potential issues, when queries done executing
and more).
2015-07-22 17:05:31 +03:00
Arik Fraimovich
a60b1686da Fix: when the server has non UTC timezone, timestamps were wrong 2015-06-03 07:58:28 +03:00