-
Notifications
You must be signed in to change notification settings - Fork 246
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
get_queryset with an abstract model #1171
Comments
Hi, so 2 observations. I put your example in a test case and it works for me without error or warnings. if getattr(self, 'swagger_fake_view', False):
return Should be enough. returning We could, in case there are no path parameters, skip the |
If I return None, I get this:
|
Something is weird here. That warning cannot be explained with your example.
The second usage is with drf-spectacular/drf_spectacular/openapi.py Line 483 in 473d2d8
drf-spectacular/drf_spectacular/plumbing.py Lines 215 to 217 in 473d2d8
this testcase works as expected for me: def test_foo(no_warnings):
class InvoiceSerializer(serializers.Serializer):
field = serializers.IntegerField()
class InvoicesList(generics.ListAPIView):
serializer_class = InvoiceSerializer
def get_queryset(self):
if getattr(self, 'swagger_fake_view', False):
return
raise RuntimeError("scheme gen should not get here")
schema = generate_schema('/x/', view=InvoicesList)
assert schema |
Does this help?
|
BTW, yes, I'm using django-filters |
your stacktrace cannot lead to that warning.
The warning must come from your usage of
what exactly do you mean with that? just a wrong schema or does it completely break with an exception? |
Yet the backtrace that I posted says otherwise, right? You're checking
but I don't have
It generates the rest of the endpoints, it just skips this particular endpoint. |
yes. this will all happen under
I'm just saying I cannot explain what you are observing with the code here. How can that |
I should also add that So that test case exactly behaves as it is supposed to: no warning and the correct operation and component. Even if I explain the warning away with django-filter (and thus a missing endpoint query parameter), it still does not explain the missing |
In |
That is what I said before! Your given stacktrace did not produce that warning because it was not in the However, all of this does not explain why the So, I cannot help you any further like that as I cannot reproduce your issue with the given information. The test case I have shown above behaves perfectly, so something else must be going on in your setup. You need to provide me a with a reproduction of your issue if you want futher assistance. |
Fair enough! I'll try to isolate the problem and provide a minimum reproducible demo. |
yes, please do.
No I don't think so. It is deliberately made like that. The path parameter extraction has fallbacks that may work and so the warning may be unnessecary or misleading. For django-filter this method is all there is and so if there is no model available, the parameter cannot be properly extracted, thus the warning. |
Describe the bug
I have a use case in which I have a ListAPIView that connects to a 3rd party (Stripe) API, fetches data (invoices) and returns that data to the user. I have a serializer, but I don't have a model.
The entire code looks something like this:
Since I don't have a model, drf-spectacular refuses to generate the proper openapi specs. It expects to receive an EmptyQuerySet (
SomeModel.objects.none()
), but I can't provide it any since I don't have anInvoice
model. I could create an abstract model like this:but I still won't be able to provide drf-spectacular with a
Invoice.objects.none()
since there is no manager in that class (and there can't be since it's abstract).How should I proceed in this scenario? Is there some workaround?
To Reproduce
N/A
Expected behavior
N/A
The text was updated successfully, but these errors were encountered: