Skip to content

Using prepare with generic foreign keys #492

@jeremy-engel

Description

@jeremy-engel

The changes in #438 prevent generic foreign keys passed to baker.prepare from being filled correctly. The _handle_generic_foreign_keys method is never called since _commit is False. The following test case added to the class TestFillingGenericForeignKeyField demonstrates the issue:

    def test_filling_generic_foreign_key_field_with_prepare(self):
        from django.contrib.contenttypes.models import ContentType

        profile = baker.make(models.Profile)
        dummy = baker.prepare(
            models.DummyGenericForeignKeyModel, content_object=profile
        )

        expected_content_type = ContentType.objects.get_for_model(models.Profile)

        assert dummy.content_object == profile
        assert dummy.content_type == expected_content_type
        assert dummy.object_id == profile.pk

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions