Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlalchemy 2.0 #6671

Closed

Conversation

AndrewChubatiuk
Copy link
Collaborator

@AndrewChubatiuk AndrewChubatiuk commented Dec 21, 2023

What type of PR is this?

Upgraded SQLAlchemy 1.3 -> 2.0

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

How is this tested?

  • Unit tests (pytest, jest)
  • E2E Tests (Cypress)
  • Manually
  • N/A

Copy link
Collaborator

@masayuki038 masayuki038 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrewChubatiuk Thanks for the PR.
However, there are many changes and it appears that the SQL Alchemy version update includes unrelated refactorings...

We would like to accurately manage what modifications have been made with SQL Alchemy version upgrades, so could you please separate the PR? I apologize for asking you to do something troublesome, but it would be a great help if you could do that. thank you.

@masayuki038
Copy link
Collaborator

@guidopetri @konnectr If it is okay to merge this from your perspective, please let me know. If so, I will consider this again.

@AndrewChubatiuk
Copy link
Collaborator Author

@masayuki038 besides:

  • removing -p option in ci
  • moving Alerts states to a separate Enum

other changes were required:

  • paginator changes were needed cause paginator function from flask-sqlachemy has changed
  • removing relative imports was related to issues in sqlalchemy
  • sort_query function was completely removed from sqlalchemy-utils, so it had to be replaced
  • all json changes were related to a bunch of issues in tests with a filtering in where clause

sqlalchemy dependencies introduce lots of changes, which do not allow to prepare tiny diffs. god bless flask and all its dependencies was not required to be upgraded together with sqlalchemy deps

@AndrewChubatiuk
Copy link
Collaborator Author

@masayuki038 could you please trigger ci from the latest commit, I've fixed lint there

@masayuki038
Copy link
Collaborator

It looks ci is running now...
https://github.com/getredash/redash/actions/runs/7298330872

@AndrewChubatiuk
Copy link
Collaborator Author

It looks ci is running now... https://github.com/getredash/redash/actions/runs/7298330872

build for a latest commit was not triggered

@masayuki038 masayuki038 self-requested a review December 22, 2023 17:19
@masayuki038 masayuki038 dismissed their stale review December 22, 2023 17:30

For some reason, CI stopped working, so I will cancel the review.

@masayuki038 masayuki038 removed their request for review December 22, 2023 17:31
@masayuki038
Copy link
Collaborator

@AndrewChubatiuk I manually re-run Github Action, but I may not have been able to fetch the latest code. I tried deleting my review, but the status did not change.

Could you try pushing something? Or could you please close this and create another PR?

@AndrewChubatiuk
Copy link
Collaborator Author

@masayuki038 please approve this pipeline
https://github.com/getredash/redash/actions/runs/7307066364

@AndrewChubatiuk
Copy link
Collaborator Author

@masayuki038 some changes were lost during rebase. pushed once again

Copy link

codecov bot commented Dec 23, 2023

Codecov Report

Attention: Patch coverage is 87.09677% with 56 lines in your changes are missing coverage. Please review.

Project coverage is 63.90%. Comparing base (b7f22b1) to head (05bbe48).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6671      +/-   ##
==========================================
+ Coverage   63.80%   63.90%   +0.09%     
==========================================
  Files         161      162       +1     
  Lines       13087    13175      +88     
  Branches     1812     1824      +12     
==========================================
+ Hits         8350     8419      +69     
- Misses       4434     4446      +12     
- Partials      303      310       +7     
Files Coverage Δ
redash/alerts.py 100.00% <100.00%> (ø)
redash/app.py 100.00% <100.00%> (ø)
redash/authentication/__init__.py 81.44% <100.00%> (+0.09%) ⬆️
redash/cli/organization.py 91.66% <100.00%> (+0.23%) ⬆️
redash/destinations/asana.py 81.48% <100.00%> (ø)
redash/handlers/alerts.py 86.74% <100.00%> (+0.16%) ⬆️
redash/handlers/data_sources.py 72.05% <100.00%> (ø)
redash/handlers/destinations.py 77.92% <100.00%> (ø)
redash/handlers/embed.py 87.50% <100.00%> (ø)
redash/handlers/organization.py 81.81% <100.00%> (+1.81%) ⬆️
... and 41 more

@konnectr
Copy link
Collaborator

I understand correctly that we are still abandoning simplejson ?

@konnectr
Copy link
Collaborator

I will try to test the operation in manual mode in the near future. It is unlikely that our auto-tests cover all possible problems

@masayuki038
Copy link
Collaborator

masayuki038 commented Dec 24, 2023

@konnectr Thanks! I will start to review this next week as well.

Copy link
Collaborator

@masayuki038 masayuki038 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrewChubatiuk
Sorry for the delay. I have finished reviewing this for now. Please check the comments.

Regarding the following points, I am not pointing out every line. If you will fix it, fix it all.

  • Please do not include updates that are not directly related to upgrading to SQLAlchemy 1.4 in this PR
    • However, I agree with your updates almost. Please separate to another PR
  • In some places, count() has been changed to len(...). Please use count()

thank you.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
redash/handlers/base.py Outdated Show resolved Hide resolved
migrations/versions/969126bd800f_.py Outdated Show resolved Hide resolved
redash/cli/organization.py Show resolved Hide resolved
redash/monitor.py Outdated Show resolved Hide resolved
redash/monitor.py Outdated Show resolved Hide resolved
redash/query_runner/databend.py Show resolved Hide resolved
redash/tasks/queries/execution.py Outdated Show resolved Hide resolved
tests/models/test_dashboards.py Outdated Show resolved Hide resolved
@AndrewChubatiuk AndrewChubatiuk force-pushed the sqlalchemy-1.4 branch 2 times, most recently from e6bd1a6 to d46a475 Compare January 3, 2024 08:33
.github/workflows/ci.yml Outdated Show resolved Hide resolved
client/cypress/cypress.js Outdated Show resolved Hide resolved
@AndrewChubatiuk
Copy link
Collaborator Author

AndrewChubatiuk commented Apr 29, 2024

@masayuki038 already checked them. answered or made code changes

@AndrewChubatiuk AndrewChubatiuk force-pushed the sqlalchemy-1.4 branch 4 times, most recently from e897b4d to 8398d6e Compare April 29, 2024 19:32
redash/models/users.py Outdated Show resolved Hide resolved
@@ -224,12 +222,10 @@ def run(self):
utcnow(),
)

updated_query_ids = models.Query.update_latest_result(query_result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this update... Could you let me know why you removed this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QueryResult and Query have relationship, there's no need to run multiple queries to store both separately (especially, when Query object already exists), doing everything in store_result function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like that Query is updated in update_latest_result.

db.session.add(q)

Can we skip this update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update_latest_result method was removed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query was updated in the method(as below).

for q in queries:
q.latest_query_data = query_result
# don't auto-update the updated_at timestamp
q.skip_updated_at = True
db.session.add(q)

Is there an alternative to this? Or have you decided that this process is not necessary? If you decide that it is unnecessary, please let us know the reason.

It seems to me that without this update, Redash's behavior will be affected. Isn't Query.lastest_query_data and some attributes no longer updated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not see contradiction, from what you've posted.

Referenced by:
   TABLE "queries" CONSTRAINT "queries_latest_query_data_id_fkey" FOREIGN KEY (latest_query_data_id) REFERENCES query_results(id)

so 1 QueryResult to many Queries

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that having Foreign Key constraints has anything to do with multiplicity.

I thought 1 Query to many QueryResults (like this).
image

Is it not correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query has latest_query_data_id attribute, which references private key in QueryResult table, which means, that multiple Query object can set the same latest_query_data_id, which means that 1 QueryResult will be referred by multiple Queries - 1 QueryResults many queries

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @masayuki038
sorry for time you've spend in a review process, but closing this PR as not going to work on redash any further

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which means, that multiple Query object can set the same latest_query_data_id,

This is the case if different Queries have the same query_hash. However, it is caused by hash value collisions, right? I don't think we should discuss it in this context.

1 Query - many QueryResults

Yes. Therefore, I think we should name query instead of queries in QueryResult. That is my point.

@AndrewChubatiuk AndrewChubatiuk force-pushed the sqlalchemy-1.4 branch 2 times, most recently from d743625 to 963fa82 Compare May 1, 2024 20:46
@AndrewChubatiuk AndrewChubatiuk force-pushed the sqlalchemy-1.4 branch 2 times, most recently from 5f3f973 to 80dab5a Compare May 2, 2024 12:13
tests/metrics/test_request.py Outdated Show resolved Hide resolved
@masayuki038
Copy link
Collaborator

@AndrewChubatiuk Could you stop to update the things other than "Sqlalchemy 2.0"?

@AndrewChubatiuk
Copy link
Collaborator Author

@AndrewChubatiuk Could you stop to update the things other than "Sqlalchemy 2.0"?

@masayuki038 i update only things, which are impacted by pr comments changes

@masayuki038
Copy link
Collaborator

masayuki038 commented May 2, 2024

@AndrewChubatiuk OK. But, I don't think we need to update "assert_called_once_with("requests.redash_ping.get", ANY)" to "assert_called" like the above thread by upgrading to SQLAlchemy 2.0... Why did you update it yesterday?

@AndrewChubatiuk
Copy link
Collaborator Author

@AndrewChubatiuk OK. But, I don't think we need to update "assert_called_once_with("requests.redash_ping.get", ANY)" to "assert_called" like the above thread by upgrading to SQLAlchemy 2.0... Why did you update it yesterday?

replied in a thread

@AndrewChubatiuk AndrewChubatiuk force-pushed the sqlalchemy-1.4 branch 3 times, most recently from f547a75 to e3cb28c Compare May 3, 2024 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants