Skip to content

TypeError: Object of type ImageFieldFile is not JSON serializable #1445

@AlexandrKovin

Description

@AlexandrKovin

Describe the bug

class Product(AbstractProduct):

    name = models.CharField(
        max_length=500, verbose_name='Product', unique=True
    )

    default_photo_url = models.ImageField(
        max_length=500,
        storage=S3Boto3Storage(),
        upload_to=product_upload_to_default,
    )

    is_active = models.BooleanField(default=True, null=False)

    history = HistoricalRecords(
        bases=[
            DiffsHistoricalModel,
        ]

    )

A historical model is being created. The default_photo_url field becomes a TextField. And when saving the product model an error occurs

File /lib/python3.11/site-packages/simple_history/models.py", line 662, in post_save
    self.create_historical_record(instance, created and "+" or "~", using=using)
  File lib/python3.11/site-packages/simple_history/models.py", line 780, in create_historical_record
    history_instance.save(using=using)
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ImageFieldFile is not JSON serializable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions