kbussell / django-jsonfield-compat

Compatibility layer for django-jsonfield and Django's native JSONField
MIT License
9 stars 15 forks source link

Avoid crashing on backward migration #5

Open PiDelport opened 6 years ago

PiDelport commented 6 years ago

Currently, when trying to migrate a django-jsonfield-compat migration backwards, the post_migrate signal handler crashes, because the schema query returns no result:

Traceback (most recent call last):
  …
  File "…/jsonfield_compat/convert.py", line 48, in handler_convert_json_fields
    convert_model_json_fields(model)
  File "…/jsonfield_compat/convert.py", line 43, in convert_model_json_fields
    convert_column_to_json(model, column_name)
  File "…/jsonfield_compat/convert.py", line 23, in convert_column_to_json
    current_type = cursor.fetchone()[0].upper()
TypeError: 'NoneType' object is not subscriptable

I ran into this while trying to unapply django-activity-stream's migrations.

This changes the code above to handle a None result, and skip the conversion in that case.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+1.2%) to 100.0% when pulling b4b5f85cf83a537487bed9a2a104e56765c89998 on pjdelport:fix-backward-migration into 5c7e967e863698683ba7999014b5cd6c80a56cf5 on kbussell:master.

ikasymov commented 4 years ago

Do you can merge this PR?