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

Fixed #35336 -- Addressed crash when adding a GeneratedField with % literals. #18027

Merged
merged 1 commit into from Apr 2, 2024

Conversation

charettes
Copy link
Member

@charettes charettes commented Mar 28, 2024

ticket-35336


A longer term solution is likely to have a better separation of parametrized DDL altogether to handle checks, constraints, defaults, and generated fields but such a change would require a significant refactor that isn't suitable for a backport.

Thanks Adrian Garcia for the report.

if params:
expression_sql = expression_sql % tuple(self.quote_value(p) for p in params)
return f"GENERATED ALWAYS AS ({expression_sql}) {persistency_sql}"
return f"GENERATED ALWAYS AS ({expression_sql}) {persistency_sql}", params
Copy link
Member Author

@charettes charettes Mar 28, 2024

Choose a reason for hiding this comment

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

The crux of the issue here is that

  1. This part was never % escaped (% -> %%) which mean that things were working properly during model creation unless the model included a database default which resulted in table_sql returning params and then interpolation kicked (see the params or None in create_model). As for add_field it systematically crashed because a list was always passed to execute(params) which triggered interpolation which is what is what was reported on ticket-35336.
  2. Postgres Some backends simply don't support parametrized DD so we should likely have a generic feature flag for it and do the quote_value dance when it's not the case in a single location. That would require changing the Constraint interfaces though as it currently return already interpolated SQL under some circumstances.

@charettes
Copy link
Member Author

This one is going to be a fun one to solve without being too invasive. I'll revisit tomorrow.

@nessita
Copy link
Contributor

nessita commented Mar 28, 2024

This one is going to be a fun one to solve without being too invasive. I'll revisit tomorrow.

Thank you Simon for working on this. I'm currently planning on delaying the next release for a few days, even a week if necessary, for two reasons:

  1. to have @sarahboyce pairing with me to do the release, and since her first day would be next Tue, it feels a bit too much to start off with a release 🤯
  2. to wait for the release blocker fix

Let me know what you think!

@charettes
Copy link
Member Author

Sounds good, I'll try to find another solution that isn't as invasive for the backport with further improvement separated to target main.

@charettes charettes force-pushed the ticket-35336 branch 2 times, most recently from cf98156 to b37f9db Compare March 31, 2024 15:42
@charettes charettes marked this pull request as ready for review March 31, 2024 17:10
@nessita
Copy link
Contributor

nessita commented Apr 1, 2024

buildbot test on oracle.

@charettes
Copy link
Member Author

It has already been tested on Oracle @nessita I just happened to delete the comment. You should see the successful status the checks.

@nessita
Copy link
Contributor

nessita commented Apr 1, 2024

It has already been tested on Oracle @nessita I just happened to delete the comment. You should see the successful status the checks.

I see it now, thank you!

@sarahboyce
Copy link
Contributor

Thank you Simon!
@AdrianGarcia-StayWithReside does it work for you?

@AdrianGarcia-StayWithReside

@sarahboyce I just gave it a try, both the example in my ticket and our actual production code worked without issue!

…iterals.

A longer term solution is likely to have a better separation of parametrized
DDL altogether to handle checks, constraints, defaults, and generated fields
but such a change would require a significant refactor that isn't suitable
for a backport.

Thanks Adrian Garcia for the report.
Copy link
Contributor

@nessita nessita left a comment

Choose a reason for hiding this comment

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

@charettes Thank you for putting together this PR!

Do you think we should Refs the related(ish) tickets in the commit message? I'm thinking about the three you mentioned (ticket-30408, ticket-34553, ticket-32369).

@charettes
Copy link
Member Author

@nessita I think it's fine to don't ref them since while they are related to the same fundamental problem they are for different features.

@nessita nessita merged commit 888b904 into django:main Apr 2, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants