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(core): Truncate db aliases if necessary #2959

Merged

Conversation

jnugh
Copy link
Contributor

@jnugh jnugh commented Jul 18, 2024

Fixes #2899

Description

Postgres truncates long identifiers making them equal if they share the same prefix. For instance if two tables are being joined with a long alias (the names need to be a lot longer in reality) product_variant_relation_0_relation_1 and product_variant_relation_0_relation_2 postgres will truncate both aliases to product_variant_rel and fail because it's not allowed to have two join statements with the same target alias.

Breaking changes

None

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

vercel bot commented Jul 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Aug 5, 2024 8:42am

Copy link
Contributor

github-actions bot commented Jul 18, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@jnugh
Copy link
Contributor Author

jnugh commented Jul 18, 2024

I have read the CLA Document and I hereby sign the CLA

@michaelbromley
Copy link
Member

Hi,

Thanks for this contribution!

Since this is quite a low-level modification, and heavily subject to the TypeORM internals, I'm wondering if there is some way we can add a test for this that:

  1. Fails before your modification
  2. Passes after it
  3. Will therefore detect regressions in future changes to TypeORM

Do you think this is something you can look into?

@jnugh jnugh force-pushed the typeorm-long-aliasses branch from 258afd1 to 03f865d Compare August 5, 2024 08:40
@jnugh
Copy link
Contributor Author

jnugh commented Aug 5, 2024

Sorry for the long delay. I implemented a test case, inside the entity hydrator test suite. Without the fix the test will fail with:

Serialized Error: { response: { errors: [ { message: 'table name "TreeEntity_childrenPropertyWithAVeryLongNameThatExceedsPostgres" specified more than once', locations: [ { line: 2, column: 3 } ], path: [ 'hydrateChannelWithVeryLongPropertyName' ] } ], data: { hydrateChannelWithVeryLongPropertyName: null }, status: 200 }, request: { query: 'query GetHydratedChannelNested($id: ID!) {\n  hydrateChannelWithVeryLongPropertyName(id: $id)\n}', variables: { id: 'T_1' } } }

@michaelbromley michaelbromley merged commit bcfcf7d into vendure-ecommerce:master Aug 14, 2024
14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2024
@michaelbromley
Copy link
Member

Excellent work, thanks so much!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EntityHydrator does not shorten jointable alias names anymore
2 participants