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

Fix compatibility with rails-head when duplicated advisory lockable column #1553

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

Earlopain
Copy link
Collaborator

The primary key and column may be identical. Current rails head will select this column twice, which confuses postgres.

Draft for now, let's first see how rails/rails#53747 goes.

The primary key and column may be identical. Current rails head will select this column twice, which confuses postgres
@@ -51,7 +51,7 @@
FROM "good_jobs"
WHERE "good_jobs"."id" IN (
WITH "rows" AS #{'MATERIALIZED' if model_class.supports_cte_materialization_specifiers?} (
SELECT "good_jobs"."id", "good_jobs"."id"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems this expectation was wrong from the start. I don't think this would execute, same as in the issue

@bensheldon
Copy link
Owner

This looks like a great fix! Simple and definitely better now 🙇🏻

@bensheldon
Copy link
Owner

I think we may as well fix this in GoodJob. I'd like to make one tweak to see if I can avoid the array/uniq calculation because I think it would be marginally more efficient to do an == check`. I can land this 🫡

@Earlopain
Copy link
Collaborator Author

Yeah, sure. You may also want to drop the to_sym conversion. I think there was one test that stubbed a symbol in but generally I think tests would catch if you pass advisory_lockable_column a symbol wich is the same as the primary key.

@bensheldon bensheldon marked this pull request as ready for review November 28, 2024 16:56
@bensheldon
Copy link
Owner

You may also want to drop the to_sym conversion.

I eventually plan to extract advisory_lockable.rb to a separate gem (I'm already using it in a few projects) so I want to be defensive about its inputs. I also wish Active Record was clear about when it wants symbols and when it wants strings; I frequently see a symbol input documented but when I go read the code it's coercing it to a string internally 🤷🏻

@bensheldon bensheldon added the bug Something isn't working label Nov 28, 2024
@bensheldon bensheldon changed the title Fix compatibility with rails-head Fix compatibility with rails-head when duplicated advisory lockable column Nov 28, 2024
@bensheldon bensheldon merged commit 43162b6 into bensheldon:main Nov 28, 2024
25 checks passed
@Earlopain Earlopain deleted the rails-head-compat branch December 3, 2024 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging this pull request may close these issues.

2 participants