Allow db only remove foreign key to work as database only - #95
Conversation
Coverage Report Results
6 empty files skipped. |
Nickmika
left a comment
There was a problem hiding this comment.
I am no expert in this library, but the test and the SQL generated looks like I would expect. Thank you. Left one comment. 👍
|
|
||
| operation.state_forwards(self.app_label, new_state) | ||
|
|
||
| # Do state only operation - has already been removed from state |
There was a problem hiding this comment.
Do state only operation - has already been removed from state
Should this read "Do database only operation"?
Remove foreign key for database was previously unable to apply as it could not find the name of the field within the state. This is modified to be able to function with only a name and model provided, even if it is not on the state by handling the error and allowing the ForeignKeyManager to be populated with an optional field value. It is noted that the Field value is still required in order for other operations to occur however.
| model_name: str, | ||
| column_name: str, | ||
| field: models.ForeignKey[models.Model], | ||
| field: models.ForeignKey[models.Model] | None, |
There was a problem hiding this comment.
🧀 It feels a little clunky to have this still being optional, but causes the add_fk_field to fail if the field is not added. Especially with having to do asserts from within the function in order to confirm that field is actually populated.
Alternative I can think of is having one manager where it is optional and another where it is not, but this seems like possible overkill
7470d0c to
1ae9b6a
Compare
marcelofern
left a comment
There was a problem hiding this comment.
Cool! I've left a comment about the CHANGELOG.md change
but please do ![]()
| - Fixed a bug where `SaferRemoveFieldForeignKey` relied on the Foreign Key also | ||
| existing in Django state, even when being performed as a database only operation. | ||
| The name and model are already provided as part of the operation. |
There was a problem hiding this comment.
Not sure if this is valid markdown list item? I.e., isn't it missing a padding on the second and third lines like the other entries below?
There was a problem hiding this comment.
Seems to be valid markdown, but makes it a "quote" instead. Have pushed a fix anyway
1ae9b6a to
798e58c
Compare
Remove foreign key for database was previously unable to apply as it could not find the name of the field within the state. This is modified to be able to function with only a name and model provided, even if it is not on the state by handling the error and allowing the ForeignKeyManager to be populated with an optional field value.
It is noted that the Field value is still required in order for other operations to occur however.
Allows the following to work: