Comments (32)
Thanks!
from prisma-client-py.
Thanks! worked perfectly
from prisma-client-py.
Is this feature available in v0.4?
I have been trying to use relation filter in where clauses but I keep getting Field does not exist on enclosing type.at
Query.findUniqueRole.where.RoleWhereUniqueInput.User.
I have tried it in some different ways:
from prisma-client-py.
@danielweil You need to wrap the relational field query with either is
or is_not
for one-to-one relations and either some
, none
or every
for one-to many / many-to-many relations.
In your case it should be:
role = await client.role.find_first(
where={
'User': {
'email': email,
},
},
)
Also it looks like you're using VSCode, if so you should definitely install the Pylance extension which will suggest the query arguments for you when you trigger auto-complete: https://github.com/RobertCraigie/prisma-client-py/blob/main/docs/showcase.gif
from prisma-client-py.
Do I have to apply any setting for the autocomplete to work? Here it still doesn't show up
from prisma-client-py.
You have to manually trigger autocomplete: https://code.visualstudio.com/docs/editor/intellisense#_intellisense-features
The Client
instance also has to be resolvable by the type checker, i.e. if you hover over it should say something like client: Client
from prisma-client-py.
It does not.
from prisma-client-py.
Ah so that's your problem, you need to annotate your get_client()
function to return prisma.Client
, e.g.
from prisma import Client
async def get_client() -> Client:
...
May I ask what your use case is for writing your own Client factory?
from prisma-client-py.
Can this be related to my python running in WSL?
I am writing it because I use Azure AD postgres JWT access to database.
from prisma-client-py.
The issue might be with any part of DBClient.instance()
then, is that correctly resolved?
from prisma-client-py.
About find_first relational query:
It gave this error message....
Failed to validate the query: Field does not exist on enclosing type.
at `Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.email
from prisma-client-py.
Can this be related to my python running in WSL?
I don't think so, I've used Python with WSL before without any issues
I am writing it because I use Azure AD postgres JWT access to database.
Ah I see, is this because you have to update the access token?
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at `Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.email
@danielweil I'm so sorry I just realised I gave you the wrong query, it should be:
role = await client.role.find_first(
where={
'User': {
'is': {
'email': email,
},
},
},
)
from prisma-client-py.
Ah I see, is this because you have to update the access token?
Yep.
About the Client type, It is very weird why it doesn't work. Check this out!
from prisma-client-py.
That is bizarre, can you share how you're importing the client please?
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at `Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.email
@danielweil I'm so sorry I just realised I gave you the wrong query, it should be:
role = await client.role.find_first( where={ 'User': { 'is': { 'email': email, }, }, }, )
Might be something here!
Failed to validate the query: Field does not exist on enclosing type.
at Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.is
from prisma-client-py.
That is bizarre, can you share how you're importing the client please?
Very
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.is
Ah sorry I missed that it was a list relation, replace is
with every
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.is
Ah sorry I missed that it was a list relation, replace
is
withevery
That worked out!
from prisma-client-py.
@danielweil Glad I could help!
About the Client type, does hovering over the import resolve correctly?
from prisma-client-py.
If that does, are you overriding the Client name anywhere?
from prisma-client-py.
It does not and I do not override it anywhere
from prisma-client-py.
That sounds like VSCode is using the wrong python interpreter then. Are you using a venv?
from prisma-client-py.
At the bottom left of your screen you should see something like this:
Click on the button that says Python ...
and select the python interpreter that you're using.
from prisma-client-py.
I opened VSCode in a remote session and now the imports show the correct class. By my get_client method still does not. I guess it is because of the async, but I can't get it to work.
On other hand, I have another issue with upsert:
I am trying to use it as a findOrCreate idea, but something in the where clause is causing an error:
Failed to validate the query: Field does not exist on enclosing type.
at `Mutation.upsertOneUser.where.UserWhereUniqueInput.email
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at `Mutation.upsertOneUser.where.UserWhereUniqueInput.email
You need to add an @unique
to the email
field definition.
model User {
//
email String @db.VarChar(255) @unique
//
}
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at `Mutation.upsertOneUser.where.UserWhereUniqueInput.email
You need to add an
@unique
to themodel User { // email String @db.VarChar(255) @unique // }
Thanks!
from prisma-client-py.
I opened VSCode in a remote session and now the imports show the correct class. By my get_client method still does not. I guess it is because of the async, but I can't get it to work.
Do you know what doesn't work? Is the Client
return type resolved correctly?
from prisma-client-py.
Not by my function:
How should it be with async functions in python? I tried Coroutine but failed.
from prisma-client-py.
The issue is that you've typed the instance()
function incorrectly. It needs to be typed to return whatever class implements the get_client()
method.
from prisma-client-py.
Failed to validate the query: Field does not exist on enclosing type. at `Query.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.email
@danielweil I'm so sorry I just realised I gave you the wrong query, it should be:
role = await client.role.find_first( where={ 'User': { 'is': { 'email': email, }, }, }, )Might be something here!
Failed to validate the query:
Field does not exist on enclosing type.
atQuery.findFirstRole.where.RoleWhereInput.User.UserListRelationFilter.is
Thanks! worked perfectly
@danielweil how did you solve this ? we tried "is", and "every" according to the documents but we can't query based on relation fields? any suggestions?
from prisma-client-py.
@farzad-salimijazi I'm sorry you're encountering difficulties, could you share your schema and the query you're trying to write so I can offer some help :)
from prisma-client-py.
Related Issues (20)
- Once event loop is closed, async client can not be used anymore. HOT 2
- Support accessing the DMMF at runtime HOT 1
- P1011: Error opening a TLS connection: bad protocol version HOT 1
- Upgrading version from 0.11.0 to 0.12.0 in Elastic Beanstalk fails deployment HOT 1
- Avoid writing to `site-packages/prisma` HOT 1
- When generator client output is set, `prisma db push` fails with Permission Denied HOT 1
- Is there a way to override use_enum_values?
- `prisma db push` does not work
- v0.13.0 - ImportError: cannot import name 'AbstractEngine' from 'prisma.engine' HOT 4
- Oracle Database not support like alchemy HOT 1
- Oracle not support HOT 1
- httpx.ConnectError: [Errno 111] Connection refused HOT 4
- RuntimeError('Event loop is closed') HOT 2
- schema.prisma on custom path HOT 3
- Bump Prisma version to latest 5.12.1
- Client extension support HOT 2
- Not working with non-ASCII paths in Windows HOT 3
- Feature Request: Add Support for Selecting Specific Fields in Prisma Python HOT 2
- prisma generate on binary in venv generates js client instead? HOT 2
- Error: spawn prisma-client-py ENOENT}
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 prisma-client-py.