Skip to content
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

Relational field access without inclusion should error #20

Closed
RobertCraigie opened this issue Jun 19, 2021 · 1 comment
Closed

Relational field access without inclusion should error #20

RobertCraigie opened this issue Jun 19, 2021 · 1 comment
Labels
kind/improvement An improvement to existing feature and code. topic: types An issue or improvement to typing
Projects

Comments

@RobertCraigie
Copy link
Owner

RobertCraigie commented Jun 19, 2021

Problem

The if branch block will never be ran, this should be caught by a type checker as it is a logical error.

As this is not possible to represent with standard python types this will need to be a supported type checker only feature.

user = await client.user.find_unique(where={'id': 'abc'})
if user.posts is not None:  # this should error when static type checking
  print(user.posts[0])

user = await client.user.find_unique(where={'id': 'abc'}, include={'posts': True})
if user.posts is not None:  # this is now valid
  print(user.posts[0])

However the following situation must still pass, this might make it very difficult (or impossible) to implement.

from prisma.models import User

def display_user_info(user: User) -> None:
  print(user.id)
  if user.posts is not None:
    print('posts: ' + ', '.join(post.id for post in user.posts))

user = await client.user.find_unique(where={'id': 'abc'})
display_user_info(user)
@RobertCraigie RobertCraigie added this to To do in v1.0.0 via automation Jun 19, 2021
@RobertCraigie RobertCraigie added kind/improvement An improvement to existing feature and code. topic: types An issue or improvement to typing labels Jun 19, 2021
@RobertCraigie
Copy link
Owner Author

Closing this as it has been deemed impossible due to the aforementioned situation.

I do not want to introduce a change that would result in false positive type errors.

v1.0.0 automation moved this from To do to Done Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. topic: types An issue or improvement to typing
Projects
Development

No branches or pull requests

1 participant