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

Broken reverse FK behaviour in Django 4.1 #347

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tests/test_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,17 @@ def test_generators_work_with_user_model(self):

@pytest.mark.django_db
class TestBakerPrepareSavingRelatedInstances:
def test_default_behaviour_for_and_fk(self):
def test_default_behaviour_for_m2m_and_fk(self):
dog = baker.prepare(models.Dog)

assert dog.pk is None
assert dog.owner.pk is None

# reverse FK access in Django 4.1 raises ValueError instead of DoesNotExist
# https://docs.djangoproject.com/en/4.1/releases/4.1/#reverse-foreign-key-changes-for-unsaved-model-instances
with pytest.raises(models.Dog.DoesNotExist):
assert dog.owner.dog_set.get()

with pytest.raises(ValueError):
assert dog.friends_with

Expand Down