Comments (6)
@shmoon-kr could build a small reproduction for us? 😊
from strawberry.
I encountered this issue while working on a project for my company, so I can't use the source code,
I've tried to reproduce the case by creating a simpler version, but it's not working.
I'm guessing that it's not the cached_property itself that's causing the problem, but rather the use of select_related with it. It's going to take me a bit more time to see what's happening more clearly and reproduce it, but I'll comment back as soon as I've simplified it and succeeded in reproducing it.
from strawberry.
@bellini666 might have some ideas then 😊
from strawberry.
Hey @shmoon-kr ,
First of all, are you using strawberry only or strawberrry_django? Based on your description, I'll assume it is strawberry_django and that you have the query optimizer enabled.
For that situation, the optimizer will call .only()
/.select_related()
on the queryset for the selected fields only. But it has to know that the fields were selected. When you retrieve something inside a cached_property
such as the age
in your example it would not know.
TBH your example would actually solve it because you are selecting birthday
together with age
, meaning that your query would guarantee that birthday
is selected, but if you remove it and only select age
then you would for sure see this problem happening.
For those cases you can give the resolver some optimization hints. Another possibility is to use a model property instead of your cached_property
, which acts the same way when you pass cached=True
to it, but does accept optimization hints as well.
Let me know if that explanation helps you. If not, a reproduction example might be required for me to understand what might be going on :)
from strawberry.
Hi. @bellini666
Yes, exactly. I'm using strawberrry_django and I enabled query optimizer.
From your description I can roughly understand what is going on.
I will try to apply your suggestions one by one. If it doesn't work, I'll talk to you again.
Thanks!
from strawberry.
The issue is completely resolved.
When I put the birthday
and age
fields in the query at the same time, django stopped making unnecessary accesses to the DB.
It's a workaround, but it's good enough for now, and since you also mentioned giving query hints, I think it's good enough.
Thanks.
from strawberry.
Related Issues (20)
- Upgrade causes "no current event loop in thread" exception HOT 1
- Opentelemetry creating one span per object HOT 1
- Mypy crashes if pydantic model and strawberry model has different fields HOT 1
- Ability to disable auto-camelcasing per field HOT 3
- `strawberry.Parent` not supporting forward refs HOT 1
- Debug server returns "ERR_INVALID_HTTP_RESPONSE" HOT 1
- Descriptions don't work with pydantic decorators HOT 2
- `Annotated` + `strawberry.lazy` + deferred annotations results in `UnresolvedFieldTypeError: Could not resolve the type of ...` errors HOT 2
- `field: None = strawberry.field()` results in `UnresolvedFieldTypeError: Could not resolve the type of ...` error HOT 1
- Changelog on PYPI redirect to error HOT 2
- `UnallowedReturnTypeForUnion` Error thrown when having a response of Union Type and using Generics since 0.229.0 release HOT 2
- Support explicit setting of federation version HOT 3
- Subgraph: "'NoneType' object has no attribute '...'" HOT 4
- oneOf is not properly exported to graphql-core library HOT 1
- Operation directives (seemingly) always erroring HOT 5
- Allow create interfaces without fields. HOT 2
- Functionality for filtering events in Subscriptions HOT 1
- Subscriptions fail to create WebSocket connections
- default_factory doesn't work HOT 11
- Wrong info type passed to resolve_reference classmethod
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 strawberry.