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

Disable Joins UUID support #47476

Merged
merged 1 commit into from Feb 27, 2023
Merged

Disable Joins UUID support #47476

merged 1 commit into from Feb 27, 2023

Conversation

sj26
Copy link
Contributor

@sj26 sj26 commented Feb 23, 2023

Motivation / Background

We're using disable_joins very successfully — thank you! — but discovered a bug when using non-integer primary keys. Some combinations of non-integer primary keys, has many through associations and order clauses invokes a disable-joins specific association cache which returns nil records. I discovered it's due to a rogue #to_i.

This PR uses the attribute type to cast values when reaching into the cache instead of presuming ids are always integers and causes appropriate records to be returned. Existing tests continue to pass.

I've added a test which demonstrates the issue, but it's pretty heavy and I'm not sure is the most appropriate place. Please advise if this test belongs somewhere else.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Copy link
Member

@eileencodes eileencodes left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! I think we can make this patch simpler though, can you try out my suggestion on your app?

@eileencodes eileencodes self-assigned this Feb 23, 2023
@eileencodes eileencodes added this to the 7.0.4 milestone Feb 23, 2023
Not all ids are integers. Existing tests still pass without the cast,
and removing the cast causes uuid joins to work.
@eileencodes eileencodes merged commit 65ae7d1 into rails:main Feb 27, 2023
eileencodes added a commit that referenced this pull request Feb 27, 2023
@eileencodes
Copy link
Member

Thank you @sj26!

Backported to 7-0-stable in cc09424

@sj26 sj26 deleted the disable-joins-uuids branch March 1, 2023 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants