8000 Fix nullable ForeignKey validation by aminalaee · Pull Request #145 · encode/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix nullable ForeignKey validation #145

8000 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

Merged
merged 2 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def target(self):
return self._target

def get_validator(self, **kwargs) -> typesystem.Field:
return self.ForeignKeyValidator()
return self.ForeignKeyValidator(**kwargs)

def get_column(self, name: str) -> sqlalchemy.Column:
target = self.target
Expand Down
9 changes: 9 additions & 0 deletions tests/test_foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,12 @@ async def test_one_to_one_crud():

with pytest.raises(exceptions):
await Person.objects.create(email="contact@encode.io", profile=profile)


async def test_nullable_foreign_key():
await Member.objects.create(email="dev@encode.io")

member = await Member.objects.get()

assert member.email == "dev@encode.io"
assert member.team.pk is None
0