Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.create and .serialize ignoring json casts #585

Closed
circulon opened this issue Feb 4, 2022 · 0 comments
Closed

.create and .serialize ignoring json casts #585

circulon opened this issue Feb 4, 2022 · 0 comments
Labels
bug An existing feature is not working as intended

Comments

@circulon
Copy link
Contributor

circulon commented Feb 4, 2022

Describe the bug
Adding a JSON cast to a models attribute I would expect a create to serialise the List assigned to the attribute into a string before saving.

To Reproduce
Note the "roles" column type is set as JSON on the db table

Steps to reproduce the behavior:
Model example:

class Employee(Model):
    __table__ = "employee"

    __casts__ = {"roles": "json"}

    __fillable__ = [
        "email",
        "roles",
    ]


# create the model
emp = Employee.creat({
    "email": "test@domain.com",
    "roles": ['admin', 'user'],
})

throws error similar to the following:
the JSON object must be str, bytes or bytearray, not list

Interestingly if I remove the casts and dump to json myself like this
"role": json.dumps(['admin', 'user'])
everything works as expected.

Looking at the JsonCast class it only passes 'dict' objects through
Ideally this should include lists as the json for them (like dicts is a direct correlation

Expected behavior
the list should be serialised and deserialised transparently in the model.

Desktop (please complete the following information):

  • OS: Mac OSX
  • Version Catalina 10.15.7

What database are you using?

  • Type: Postgres
    • Version 10.5
  • Masonite ORM v2.2.0
@circulon circulon added the bug An existing feature is not working as intended label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants