Skip to content

Calling update_change_reason on a null JSONField with a postgres DB raise an AttributeError #1181

Open
@helenecourau

Description

@helenecourau

Describe the bug
I use a postgres database. I call the update_change_reason method in a post_create_historical_record signal and my model has a nullable JSONField. It raises an AttributeError 'NoneType' object has no attribute 'history_change_reason'.

To Reproduce
Steps to reproduce the behavior:

  1. Create a model with a null JSONField on a project with a postgres database.
  2. Register the history on all fields.
  3. Call the update_change_reason method.
  4. It raises an AttributeError 'NoneType' object has no attribute 'history_change_reason'.

Expected behavior
No error raised.

Screenshots

Environment (please complete the following information):

  • OS: MacOS 13.3.1
  • Django Simple History Version: 3.3.0
  • Django Version: 4.0.1
  • Database Version: PostgreSQL 14.8

Additional context

The problem is that update_change_reason makes this request : model.objects.filter(json_field=None)
For a postgres JSONField, None means that there is a null value and in this case there is no null value just an empty field.

I tried to override locally the update_change_reason method to make this request for the null jsonfield: model.objects.filter(json_field__isnull=True) and it works.
If it's usefull I can open a pull request with this change.

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