-
Notifications
You must be signed in to change notification settings - Fork 152
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
Issue with id
after upgrading from 0.30.1 to 0.31.0
#193
Comments
The id field is included into the attributes of the object before schema validation. So it seems that your schema does not include an id field or your id field get the attribute dump_only ? |
I also hit this issue, and I tried remove the "dump_only" from id field and still get the same issue. Is there other possible reason for this issue to happen? |
@akira-dev I also face the same issue.
It seems that the only way to avoid this is to remove the |
Came here to report this. This seems like a bug to me. I've been deep in the flask-rest-jsonapi/marshmallow-jsonapi/marshmallow code all day, and I finally found this in marshmallow-jsonapi's
This seems incorrect to me. My schema has Modifying the method above and commenting out the last two quoted lines fixes the problem, and at least in my application has no negative side-effect at all. I'm going to play with this a bit more to confirm, but I'm reasonably-confident at this point that it's a bug, and plan to fork marshmallow-jsonapi and/or flask-rest-jsonapi to fix it. I'm not sure if the maintainers of either of these repos are active as there haven't been any changes for a few months. |
I was able to work around this in a much simpler way via the following:
Similarly in my
This is much cleaner/less-hacky than my proposal above. Thankfully flask-rest-jsonapi includes these nice hooks for manipulating the data. |
Better fix would be to remove the id using pre_load, which is called before deserializing from marshmallow import pre_load
class FooSchema(Schema):
class Meta:
type_ = 'foo'
self_view = 'foo_detail'
self_view_kwargs = {'id': '<id>'}
self_view_many = 'foo_list'
@pre_load
def remove_id_before_deserializing(self, data, **kwargs):
if 'id' in data:
del data['id']
return data
id = fields.UUID(as_string=True, dump_only=True)
name = fields.Str(required=True)
class FooDetail(ResourceDetail):
schema = FooSchema
data_layer = {
'session': db.session,
'model': Foo,
}
methods = ['GET', 'PATCH']
class FooList(ResourceList):
schema = FooSchema
data_layer = {
'session': db.session,
'model': Foo,
}
methods = ['GET', 'POST'] |
I don't know but for me you can safely remove dump_only, because in code of ResourceDetail is this part
For POST in specification you can allow or dissallow set id. |
I have this issue after upgrading from 0.30.1 to 0.31.0 or 0.31.2
The reads work, but my update is failing.
Is anyone else having this issue? Or maybe there is a change with the new dependency libraries?
The text was updated successfully, but these errors were encountered: