Comments (4)
try pre fetching also artist_set
Card.objects.prefetch_related("cardhold_set", "artist_set")
from django-ninja.
try pre fetching also artist_set
Card.objects.prefetch_related("cardhold_set", "artist_set")
Hi @vitalik thanks for your response.
I tried that and get the following:
Traceback (most recent call last):
File "/Users/christophercarvalho/ninja/env/lib/python3.11/site-packages/ninja/operation.py", line 282, in run
return self._result_to_response(request, result, temporal_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/christophercarvalho/ninja/env/lib/python3.11/site-packages/ninja/operation.py", line 208, in _result_to_response
validated_object = response_model.model_validate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/christophercarvalho/ninja/env/lib/python3.11/site-packages/pydantic/main.py", line 532, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for NinjaResponseSchema
response
Error extracting attribute: SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async. [type=get_attribute_error, input_value=<DjangoGetter: <ninja.ope... object at 0x1136c23d0>>, input_type=DjangoGetter]
For further information visit https://errors.pydantic.dev/2.7/v/get_attribute_error
from django-ninja.
yeah, maybe prefetch_related does not support async yet..
try:
@api.get("/get-cards", response=List[CardOut])
@decorate_view(cache_page(7 * 24 * 60 * 60))
async def list_cards(request):
queryset = Card.objects.prefetch_related("cardhold_set", "artist_set")
cards = await sync_to_async(list)(queryset) # force executing db query here by converting to list
return cards
from django-ninja.
yeah, maybe prefetch_related does not support async yet..
try:
@api.get("/get-cards", response=List[CardOut]) @decorate_view(cache_page(7 * 24 * 60 * 60)) async def list_cards(request): queryset = Card.objects.prefetch_related("cardhold_set", "artist_set") cards = await sync_to_async(list)(queryset) # force executing db query here by converting to list return cards
I think you might be right, it doesn't work when I include artist_set, song, or cardhold_set in the schema
from django-ninja.
Related Issues (20)
- Static Method Not Reflecting Instance-Specific Argument in Dynamically Created ModelSchema Class
- [BUG] `fields_optional="__all__"` causes TypeError on models with a field using the `default` parameter HOT 1
- [BUG] `SmallAutoField` missing from `ninja.orm.fields` HOT 1
- Add Redoc Try It Out feature
- Adding the schema for "unauthorized" to the OpenAPI
- The CSRF header name needs to be configurable HOT 2
- create_schema w/ depth: Support ReverseManyToOneDescriptor
- Make `csrf=True` add `X-CSRFToken` header parameters to OpenAPI spec HOT 2
- Docs not updated? HOT 4
- [BUG] Cannot use Django's Test Client when Ninja TestClient is used in a pytest suite HOT 3
- Allow optional fields to be marked as required in `ModelSchema`
- [BUG] Self-Referencing Schemas are Broken HOT 1
- How to implement a generic Filter HOT 1
- [BUG] URL path recognition error when get request comes first and post request comes later
- can you implement websocket for ninja api.
- Documentation of responses with schemes in openapi_extra
- [BUG] ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' on python 3.12.4
- [BUG] Endpoint payload cannot be an Annotated Union with Discriminator
- Returning alternate response objects HOT 1
- [BUG] mypy crashes with django-ninja installed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-ninja.