Fix bulk_update raising syntax error for ForeignKey fields#2126
Open
Br1an67 wants to merge 2 commits intotortoise:developfrom
Open
Fix bulk_update raising syntax error for ForeignKey fields#2126Br1an67 wants to merge 2 commits intotortoise:developfrom
Br1an67 wants to merge 2 commits intotortoise:developfrom
Conversation
Member
|
@Br1an67 Also check linter here, pls |
12436d0 to
bc8c9f8
Compare
When bulk_update was called with a ForeignKey field name (e.g., fields=['post']), the generated SQL used the Python object repr instead of the FK column value, causing a syntax error. Now FK fields are properly resolved to their source_field column name and the related object's PK value is used in the SQL.
bc8c9f8 to
030a778
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
bulk_updatewas called with a ForeignKey field name (e.g.,fields=['post']), the generated SQL used the Python object repr (e.g.,<Post>) instead of the FK column value, causing a syntax error likenear "<": syntax error.The fix resolves FK fields to their
source_fieldcolumn name and extracts the related object's PK value, matching the behavior of the regularUpdateQuery.Motivation and Context
Fixes #1335
Using
fields=['post_id']worked as a workaround, butfields=['post'](the FK field name) should also work, as it does for regular.update()queries.How Has This Been Tested?
Added
test_bulk_update_foreign_keythat:bulk_update(events, fields=['tournament'])All 8 existing bulk_update tests continue to pass.
Checklist: