Marshmallow 3.0.1 - 'NoneType' object has no attribute 'opts' #131
Comments
Thanks for reporting. I unfortunately won't have time to do a code dive in the near future. Feel free to send a PR if you figure it out. |
This seems to be an easy fix in schema.py or fields.py on some marshmallow change to The self.root, what does it represent? Was there any change on the marshmallow side of things? |
|
I actually can, this project is opensource: Find the urls/routing in the default app of the project |
Cool; do you know which schema is raising the error? |
All of 'm! Every endpoint using any Schema derivative is throwing the error. Also: the stacktrace is not pointing to any of my files, so that's why I thought there must be an incompatibility issue. In this case UserSchema shows it, but any other does as well |
Have you tried upgrading your marshmallow version? We currently test this package against the latest marshmallow 3.x (3.4.0 as of this writing) and DRF 3.{8,9}. |
Yes I did :) Both updated DRF and MM showed the same problems, so I had to take steps back in my Pipfile. I tried Django, DRF, MM and DRF-MM, until I noticed it started working. I re-upgraded everything to find DRF-MM 3.0.0 -> 3.0.1 (and beyond) to be the problem. Will try again tonight |
So the issue for this one and for #110 is that marshmallow base expects parent to not exist. When searching for root it does this:
Notice how the code checks the for the existence of the parent field. So it expects it not to be there. If parent is is parent on ret but is null, this method returns null and thus you have the error outlined above in this method in marshmallow.fields.DateTime
The error happens becuse root is None. Now the question remains... why is parent None and not not present? This is because there is a parent field initialised to None in django-rest-framework/rest_framework/fields.py#358 For one thing, the test is simple, just add a date field to the ExampleSerializer schema in the tests... Now consider:
and
Notice how it looks for None parent and not parent that is not present - consistent with the code in So what to do? I don't think we can switch to using the other root method as the constructor of Schema explicitly calls
So considering:
The only alternative, in my opinion, is to change the semantics of the parent field to match what marshmallow expects - that is, delete the attribute. So in the pull request in Schema the code
has a delattr inserted between:
|
Great work! @sloria, kindly check this hero's work out, if you find the time. |
Fix released in 4.0.2 |
@sloria thank you so much merging and releasing so quickly. Wow, I was surprised. Never had a pull accepted that quickly before. I'm desperate for the fix but it has not reflected on pypi yet... Comparing the 4.0.1 build logs to 4.0.2 build logs it seems that 4.0.2 did not run the Pypi release stage... see 4.0.1 and 4.0.2 It makes no sense as I can't see any difference between the builds. |
Ah, travis doesn't like the config unfortunately I won't have time to look into this today; @michaelwiles would you like to do some digging on how to get |
Looking into the travis issues in #136 |
P.S. we should really switch to Azure Pipelines to get this project in line with the rest of marshmallow-code... just haven't had the time.. =/ |
[Moved answer about Azure to new issue #139] |
Exception Value: 'NoneType' object has no attribute 'opts'
Description: when updating marshmallow from 3.0.0 to 3.0.1, all my API endpoints using any marshmallow serializer get this error. @sloria I am not sure if this is mmallow or django-mmallow
Expected behaviour: being able to use django 4.0+ and marshmallow 3.4 in combination with this interfacing library without error.
Pipfile extract:
Working version (before changing to marshmallow 3.0.1).
Complete error trace:
The text was updated successfully, but these errors were encountered: