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

New load method #583

Open
hmleal opened this issue Jan 21, 2019 · 0 comments
Open

New load method #583

hmleal opened this issue Jan 21, 2019 · 0 comments

Comments

@hmleal
Copy link

hmleal commented Jan 21, 2019

With the current API, I think it's too hard to serialize an object to JSON or the errors of this object. This is why I think it would be nice to have a new method called load. I think it should work like that:

Actual scenario (trying to return a JSON of the data or errors)

class Person(Model):
  name = StringType(required=True)

data = Person({})
try:
  data.validate()
  return json.dumps(data.serialize())
except Exception as e:
  return json.dumps(e.to_primitive())

If you want to use this in API it will be much more interest something like this:

Proposal

class Person(Model):
  name = StringType(required=True)

obj, errors = Person().load({})

if errors:
  return json.dumps(errors)
return json.dumps(obj.serialize())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant