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: knex withSchema.raw error #14839

Merged
merged 5 commits into from Nov 16, 2022
Merged

Fix: knex withSchema.raw error #14839

merged 5 commits into from Nov 16, 2022

Conversation

jhoward1994
Copy link
Contributor

@jhoward1994 jhoward1994 commented Nov 11, 2022

We received a bug report with v4.5.0 for Postgres DBs that are using the schema option in config/database.js

What does it do?

fixes #14832

How to test it?

Follow instructions in #14832

Related issue(s)/PR(s)

#14832
closes #14887 - Thank you for the work @zodman 🙏, I just had to make a couple of tweaks

Note: we have decided to not handle multiple PG schemas in this fix to avoid inconsistency. Theres are other places in the codebase where a similar fix will be required. They will all be handled together

@jhoward1994 jhoward1994 added the pr: fix This PR is fixing a bug label Nov 11, 2022
@jhoward1994 jhoward1994 self-assigned this Nov 11, 2022
@jhoward1994 jhoward1994 marked this pull request as draft November 11, 2022 12:18
@jhoward1994 jhoward1994 added the source: core:database Source is core/database package label Nov 11, 2022
@codecov
Copy link

codecov bot commented Nov 11, 2022

Codecov Report

Base: 59.33% // Head: 59.76% // Increases project coverage by +0.43% 🎉

Coverage data is based on head (0429557) compared to base (68d63ab).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14839      +/-   ##
==========================================
+ Coverage   59.33%   59.76%   +0.43%     
==========================================
  Files        1338     1339       +1     
  Lines       32726    32669      -57     
  Branches     6199     6189      -10     
==========================================
+ Hits        19417    19526     +109     
+ Misses      11440    11296     -144     
+ Partials     1869     1847      -22     
Flag Coverage Δ
front 64.28% <ø> (+0.64%) ⬆️
unit 49.80% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...e/database/lib/entity-manager/regular-relations.js 9.19% <0.00%> (ø)
...mponents/DynamicZone/components/Component/index.js
...ts/ComponentPicker/Category/ComponentCard/index.js
...ts/DynamicZone/components/ComponentPicker/index.js
...components/DynamicZone/components/DzLabel/index.js
...DynamicZone/components/AddComponentButton/index.js
...ents/DynamicZone/components/Component/Rectangle.js
...cZone/components/ComponentPicker/Category/index.js
...onents/DynamicZone/components/ComponentCategory.js 100.00% <0.00%> (ø)
...components/DynamicZone/components/ComponentCard.js 100.00% <0.00%> (ø)
... and 8 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jhoward1994 jhoward1994 marked this pull request as ready for review November 14, 2022 16:40
@jhoward1994 jhoward1994 marked this pull request as draft November 15, 2022 17:11
const schema = this.connection.getSchemaName();
const connection = tableName ? this.connection(tableName) : this.connection;
return schema ? connection.withSchema(schema) : connection;
return tableName ? this.connection(tableName) : this.connection;
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on what we discussed, I think we should not change the code here and instead use connection instead of getConnection. WDYT?

chore(database): revert getConnection()
@jhoward1994 jhoward1994 marked this pull request as ready for review November 16, 2022 09:53
WHERE ${where.join(' OR ')}
) AS b
WHERE b.id = a.id`,
[joinTableName, ...updateBinding, ...selectBinding, joinTableName, ...whereBinding]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it works. I think you need to do ??.?? and [schemaName, joinTableName, ...] as each argument is either an identifier or a value. ${schemaName}.${joinTableName} would be 2 identifiers at the same time. Did you try it?

I think you can either:

  • directly put the value in the query, not using the arguments
  • don't handle the schema for now, we will do it in another PR anyway as there are other parts of the app that needs to be fixed with the schema

I would suggest the second options so we can also take the time to do it (not doing it during the rush)

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently that works indeed! https://knexjs.org/guide/ref.html#ref
Capture d’écran 2022-11-16 à 11 56 05

Good to know. However I would still not do that in that PR for the moment as it would be add some inconsistency

@jhoward1994 jhoward1994 added this to the 4.5.1 milestone Nov 16, 2022
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

LGTM :)

@jhoward1994 jhoward1994 merged commit 49c4ba2 into main Nov 16, 2022
@jhoward1994 jhoward1994 deleted the fix/relations-knex-raw branch November 16, 2022 12:27
@zodman
Copy link

zodman commented Nov 16, 2022

@petersg83 then you drop support for running strapi in different schema ?

I have strapi setup in supabase, where the default schema is public, and strapi behind schema cms, what options have?

  searchPath: ['postgres', 'cms'],

?

@petersg83
Copy link
Contributor

@zodman
No, we discovered yesterday that we have issues with postgres schema since a long time ago. So we will fix all of them for the next patch release (instead of this one).
What Strapi version do you use?

@zodman
Copy link

zodman commented Nov 16, 2022

@petersg83 2.5.0

@petersg83
Copy link
Contributor

Can you check again ? This one doesn't exist :P

@zodman
Copy link

zodman commented Nov 16, 2022

@petersg83

│ Version            │ 4.5.0 (node v16.15.1)                            │
│ Edition            │ Community            

@alexghattas
Copy link

@zodman No, we discovered yesterday that we have issues with postgres schema since a long time ago. So we will fix all of them for the next patch release (instead of this one). What Strapi version do you use?

@petersg83 do you have a current fix for this? Do we need to downgrade it? Change something else? This currently leaves our Strapi in a state where we cannot edit any articles in production, any guidance would be greatly appreciated!

@petersg83
Copy link
Contributor

Hello @alexghattas :) It's should be fixed in 4.5.2 :)

@alexghattas
Copy link

Hello @alexghattas :) It's should be fixed in 4.5.2 :)

Thank you @petersg83, confirming its fixed the issue on our end :)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:database Source is core/database package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot save content after upgrading to 4.5.0
4 participants