-
Notifications
You must be signed in to change notification settings - Fork 260
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
AssertionError Serializer #120
Comments
hey! it is nearly impossible to guess what went wrong there. all i can see that it is probably a heavily nested serializer (which should be ok) and that the assert got hit by something that was not a serializer. this should be a very unlikely event. i would need some kind of serializer example or reproduction on how to provoke the error. |
I just hit this. I suggest that assert is never used without a second arg which explains the failed assertion. There are code quality tools which can enforce this. If you want these assertions to cause issues to be raised, it helps to have assertion messages let people raise bugs which can be used to identify the problem. Since this component is py36+, it could also use And as usual, I would prefer these are warnings. In my case it is a custom lazy-ily defined serializer and it could be safely ignored as inspecting it wont work anyway. The following worked for me. - assert is_serializer(serializer)
+ if not is_serializer(serializer):
+ return |
certainly something to consider. i did not anticipate this being hit, except for very rare cases. i'll look into it whether a more meaningful assert message or a non-fatal error/warn is more appropriate.
@danilocastelhano1 which library with customized serializer logic did you use? |
@jayvdb i had another look and i remember now. that assertion is supposed to be just that,a is a basic assumption that "must" hold true. (Almost) all callers of that function ensure that assumption and if not throw a warning and do a fallback. The only way i can see to get there unchecked is by either using can you elaborate on how you got that error? that would be most helpful. i might have missed a case somewhere. |
@tfranzel i use docusign library, there is a big serializer in there |
@danilocastelhano1 i see.
|
in docusign, I use customizable serializers, I believe this is what is causing the exception, if I change my serializer to one that is: MySerializer (serializers.ModelSerializer), it works correctly, but if I create a customizable serializer: eg: MyCustomSerializer ( serializers.Serializer), generate the mentioned error. |
ahh i understand, but customized serializers should never provoke this error, as long as they are based on pretty much every test we have is using this, where it has never been a problem. example: also the check is pretty trivial: drf-spectacular/drf_spectacular/plumbing.py Lines 102 to 107 in 7600cbe
are you sure you are actually using |
i think i found the error, it is in:
when i use ListSerializer, gives the error above, ListSerializer belongs to rest_framework->serializers.py |
You have missed the case where the serializer doesnt inherit from those classes. :-) |
@danilocastelhano1 ... ahh that makes absolute sense! now we are getting to the bottom of it. DRF automatically translates
|
@jayvdb well i wouldn't call that missed. that is on purpose. DRF required the We have |
I think it is official, because in drf-yasg works good, and in drf-spectacular gives the error You can create an serializer: and a viewset: |
@danilocastelhano1 well that was a surprise! i validated that it works on the API as you said. today i learnt something new 😄 ListSerializer accepts |
Glad to help and improve the tool. tks. |
@danilocastelhano1 can you check if that works for you? close if issue is resolved. fwiw, my confusion came from the fact that there is a dedicated class for exactly that purpose: |
I agree. I just wish you didnt force failure on my entire API because of one part of it that I dont want or expect to be exposed in the OpenAPI. |
morning guys, how can i test? by pip install drf-spectacular? first i ran pip uninstall drf-spectacular then i ran pip install drf-spectacular so the error persists, i noted that file: openapi.py do not changed, in github the file (https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/openapi.py) has 943 lines vs 933 when i ran pip install drf-spectacular |
morning!
should do it. then you have the current master state |
Nice @tfranzel Woked good thanks a lot! |
i have an serializer who give me an exception, follow my traceback:
The text was updated successfully, but these errors were encountered: