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 creation of model instances with related model fields #164

Merged
merged 4 commits into from
Mar 12, 2021

Conversation

amureki
Copy link
Collaborator

@amureki amureki commented Mar 9, 2021

#117 introduced an issue for two cases :

  • where id value is provided as default for foreign key
  • where foreign key is defaulting to None, but we overwrite this default by some value

See discussion in #136 that led to a current solution (first fix attempt was different, see 035281c).

This PR attempts to fix that issue by checking if the field has a default AND not overwritten in self.rel_fields.
I've added test cases, kindly suggested by @cb109 in #136.

#117 introduced an issue for cases where `id` values is provided as a default for foreign keys.
This PR attempts to fix that issue by checking if generated value for FK field is an instance of this model - if not it uses `_id` as a field name (https://docs.djangoproject.com/en/3.1/ref/models/fields/#database-representation).
@amureki amureki force-pushed the issues/136/fix_fk_regression branch from 480e51c to 73ac0d3 Compare March 10, 2021 18:18
@amureki amureki changed the title Allow id to be used as FK default (Fix #136) Fix creation of model instances with related model fields Mar 11, 2021
@amureki amureki marked this pull request as ready for review March 11, 2021 23:03
Copy link
Member

@berinhard berinhard left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix @amureki! I'll prepare a new release today

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

Successfully merging this pull request may close these issues.

[BUG] v1.2.1 breaks usage of baker.make(related_model__field=value)
2 participants