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

Create sqlalchemy_searchable expressions #6491

Merged

Conversation

azundo
Copy link
Contributor

@azundo azundo commented Sep 30, 2023

The required sql expressions for sqlalchemy_searchable are only created on the sqlalchemy pre_create hook. When upgrading from a previous redash version, there may be no CREATE statements in any applicable migrations, so these sql expressions are never created.

In a fresh install the hook runs properly so there's no issue with the search functionality.

Add a migration to manually execute the sql_expressions DDL from sqlalchemy_searchable.

What type of PR is this?

  • Bug Fix

Description

The required sql expressions for sqlalchemy_searchable are only created on the sqlalchemy pre_create hook. When upgrading from a previous redash version no CREATE statements may be run, so these expressions are never created.

How is this tested?

  • Manually
  1. Created a fresh install of redash from the current master branch and deleted the custom sql expressions created by sqlalchemy_searchable. This mimics the state of an installation that was upgraded from a version prior to the version bump of sqlalchemy_searchable.
  2. Confirmed that search is broken.
  3. Deployed fix and ran migrations.
  4. Confirmed search is fixed.

Related Tickets & Documents

Fixes #6381

The required sql expressions for sqlalchemy_searchable are only created
on the sqlalchemy pre_create hook. When upgrading from a previous redash
version no CREATE statements may be run, so these expressions are never
created.

Add a migration to manually execute the sql_expressions DDL from
sqlalchemy_searchable.
@azundo azundo mentioned this pull request Sep 30, 2023
@codecov
Copy link

codecov bot commented Sep 30, 2023

Codecov Report

Merging #6491 (1849724) into master (1d35085) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #6491   +/-   ##
=======================================
  Coverage   61.26%   61.26%           
=======================================
  Files         158      158           
  Lines       12889    12889           
  Branches     1755     1755           
=======================================
  Hits         7896     7896           
  Misses       4743     4743           
  Partials      250      250           

@justinclift
Copy link
Member

Thanks @azundo, this looks useful. I'm trying to solve a different problem this weekend (Trino related), but this shouldn't be too hard to test too anyway.

@eradman
Copy link
Collaborator

eradman commented Sep 30, 2023

@azundo do you think this would also solve #6448?

When we tried switching to SQLAlchemy-Utils to 0.36.5 we hit errors when upgrading an existing install.

@azundo
Copy link
Contributor Author

azundo commented Sep 30, 2023

@justinclift I was finally able to manually test it so I have at least run the migration code and confirmed it works as expected, but probably worth having someone else confirm as well. It's a bit awkward to reproduce the exact scenario of installing an older version and then upgrading. I simulated this instead by deleting all the SQL expressions created by sqlalchemy searchable so search would fail again, and then running the redash migration to confirm the fix.

@eradman that issue doesn't look related to me at first glance

@justinclift
Copy link
Member

Sorry for the delay in reviewing this. I have this on my ToDo list for the next few days though. It's not forgotten. 😄

@azundo
Copy link
Contributor Author

azundo commented Oct 3, 2023

No worries at all! The workaround I shared in the bug report is an easy fix for anyone running into this so I wouldn't say it's urgent.

@denisov-vlad
Copy link
Member

Hi!

@azundo @justinclift I've tested it both on my dev server and production cluster, and everything works fine.

@eradman Also tested updating to SQLAlchemy-Utils==0.36.5, the same error as before. :(

@Krikooo
Copy link

Krikooo commented Oct 12, 2023

I tested this PR, it's work just like a charm.
Thank you for your work @azundo 👍

@justinclift
Copy link
Member

Awesome. Thanks for verifying it @Krikooo. Merging it now. 😄

@justinclift justinclift enabled auto-merge (squash) October 12, 2023 17:05
@justinclift justinclift merged commit abbd4d3 into getredash:master Oct 12, 2023
13 checks passed
@pinophyta
Copy link

What's the proper way to run this migration after upgrading redash?

@eradman
Copy link
Collaborator

eradman commented Jan 4, 2024

@pinophyta try

docker compose run --rm server manage db upgrade

or if not using docker

$REDASH_DIR/bin/manage db upgrade

@pinophyta
Copy link

Thank you very much @eradman. That worked and I was able to upgrade to latest dev tag 🥳

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.

Query Search is broken
6 participants