[Django] PolymorphicEmbeddedModelField raises TypeError when saving a model instance

XMLWordPrintableJSON

    • None
    • Python Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Saving a Django model that contains a PolymorphicEmbeddedModelField or PolymorphicEmbeddedModelArrayField with a non-null value raises:

       TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

        This occurs in PolymorphicEmbeddedModelField.get_db_prep_save because self.embedded_models is stored as a list (as passed by the user) but isinstance() requires a tuple as its second argument.

      Steps to reproduce:

         class Dog(EmbeddedModel):
            name = models.CharField(max_length=100)
      
        class Cat(EmbeddedModel):
            name = models.CharField(max_length=100)
      
        class PetOwner(models.Model):
            pet = PolymorphicEmbeddedModelField([Dog, Cat], null=True)
      
        PetOwner.objects.create(pet=Dog(name="Rex"))  # raises TypeError

      Expected behavior: The instance is saved successfully.

      Affected code: django_mongodb_backend/fields/polymorphic_embedded_model.py, get_db_prep_save (two call sites).

      I encountered this bug while working on INTPYTHON-771.

            Assignee:
            Tim Graham
            Reporter:
            Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: