-
Notifications
You must be signed in to change notification settings - Fork 95
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
fix #336: detecting relationship as nullable=False #458
base: dev
Are you sure you want to change the base?
Conversation
@@ -348,7 +348,7 @@ def _add_relationship_kwargs(self, kwargs, prop): | |||
nullable = True | |||
for pair in prop.local_remote_pairs: | |||
if not pair[0].nullable: | |||
if prop.uselist is True: | |||
if not self.DIRECTION_MAPPING[prop.direction.name]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handling 2 cases:
- For anything which has a list - we expect an empty list - and so nullable=False
- And for anything which has a FK on the table itself - we should consider the nullable from the FK (MANYTOONE case)
if not pair[0].nullable:
if prop.uselist is True or self.DIRECTION_MAPPING[prop.direction.name] is False:
nullable = False
continue
MANYTOONE case:
class Book:
...
author_id = Column(Integer, ForeignKey('author.id'), nullable=False)
author = relationship('Author', lazy='selectin')
MANYTOMANY case with uselist=True:
class Book:
...
author = relationship('Author', secondary=book_author, lazy='selectin', uselist=True)
MANYTOMANY case with uselist=False:
class Book:
...
author = relationship('Author', secondary=book_author, lazy='selectin', uselist=False)
Can we add testcases for various direction X uselist scenarios ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AbdealiJK ,
Have updated the changes based on the feedback in comment
8adcc14
to
ee0d2a5
Compare
@indiVar0508 could you please rebase this? @AbdealiLoKo review welcome after rebase. Thanks guys! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase again to get the latest changes (SQLAlchemy 2.0).
Thanks.
tests/test_conversion.py
Outdated
@@ -354,6 +354,49 @@ class ModelWithArray(Base): | |||
assert field.dump_only is True | |||
|
|||
|
|||
class TestRelationShipKwarg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestRelationshipKwarg
tests/test_conversion.py
Outdated
def test_many_to_one_relationship_kwarg(self, models): | ||
default_converter = ModelConverter() | ||
|
||
rel = models.Student.__mapper__.get_property("current_school") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use get_property but .attrs (see #495).
Hello @lafrech and @AbdealiLoKo this PR has not moved since a year. Do you know if anyone will work on it in the next days/week? Regards |
Attempt to address #336,
using direction mapping to decide if nullable is to be set False or not
pytest result for new branch:
94 passed, 55 warnings
pytest in master :
94 passed, 55 warnings