model-bakers/model_bakery

TypeError: <class 'jsonfield.fields.JSONField'> is not supported by baker.

marcosschroh opened this issue ยท 4 comments

Describe the issue
JSONField is not supported. According to this #85 the support for JSONField was added but it is not working.

To Reproduce
Having a model with a JSONField and then call baker.make(the_model)

Traceback

src/tests/streaming/test_stream_product.py:16: in test_serialize_product
    product = baker.make(Product)
venv/lib/python3.11/site-packages/model_bakery/baker.py:130: in make
    return baker.make(
venv/lib/python3.11/site-packages/model_bakery/baker.py:385: in make
    return self._make(**params)
venv/lib/python3.11/site-packages/model_bakery/baker.py:452: in _make
    self.model_attrs[field.name] = self.generate_value(
venv/lib/python3.11/site-packages/model_bakery/baker.py:680: in generate_value
    raise TypeError(
E   TypeError: field possible_costs type <class 'jsonfield.fields.JSONField'> is not supported by baker.
------------------------------------------------------ Captured stderr setup ------------------------------

Versions

  • Python: 3.11
  • Django: 4.1.5
  • jsonfield: 3.1.0
  • Model Bakery: 1.12.0

Model Bakery supports Django's native JSONField, not the third-party implementation you're using. You'll have to write a custom field generator.

Thanks @samamorgan for jumping in here and adding explanatory links ๐Ÿ‘

@marcosschroh does this answer to your issue? Also, I am curious, what is the reason for you to use a custom JSONField implementation and not a native one?

Also, I am curious, what is the reason for you to use a custom JSONField implementation and not a native one?

Same. The docs for that library specifically recommend using the native JSONField.

Yes, that answer my question @amureki . Thanks