Skip to content

Commit

Permalink
Merge pull request #25 from superlevure/revert/PR-1380
Browse files Browse the repository at this point in the history
fix: revert PR-1380
  • Loading branch information
superlevure authored Jul 26, 2023
2 parents d171106 + b8f8411 commit b910ab2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
3 changes: 3 additions & 0 deletions graphene_django/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,9 @@ class Query(graphene.ObjectType):
assert result.data == expected


@pytest.mark.xfail(
reason="Until https://github.com/graphql-python/graphene-django/pull/1380#issuecomment-1646331317 is fixed."
)
def test_model_inheritance_support_reverse_relationships():
"""
This test asserts that we can query reverse relationships for all Reporters and proxied Reporters and multi table Reporters.
Expand Down
3 changes: 3 additions & 0 deletions graphene_django/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def test_get_model_fields_no_duplication():
assert len(film_fields) == len(film_name_set)


@pytest.mark.xfail(
reason="Until https://github.com/graphql-python/graphene-django/pull/1380#issuecomment-1646331317 is fixed."
)
def test_get_reverse_fields_includes_proxied_models():
reporter_fields = get_reverse_fields(Reporter, [])
cnn_reporter_fields = get_reverse_fields(CNNReporter, [])
Expand Down
29 changes: 11 additions & 18 deletions graphene_django/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,17 @@ def _get_model_ancestry(model):


def get_reverse_fields(model, local_field_names):
"""
Searches through the model's ancestry and gets reverse relationships the models
Yields a tuple of (field.name, field)
"""
model_ancestry = _get_model_ancestry(model)

for _model in model_ancestry:
for name, attr in _model.__dict__.items():
# Don't duplicate any local fields
if name in local_field_names:
continue

# "rel" for FK and M2M relations and "related" for O2O Relations
related = getattr(attr, "rel", None) or getattr(attr, "related", None)
if isinstance(related, models.ManyToOneRel):
yield (name, related)
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
yield (name, related)
for name, attr in model.__dict__.items():
# Don't duplicate any local fields
if name in local_field_names:
continue

# "rel" for FK and M2M relations and "related" for O2O Relations
related = getattr(attr, "rel", None) or getattr(attr, "related", None)
if isinstance(related, models.ManyToOneRel):
yield (name, related)
elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
yield (name, related)


def get_local_fields(model):
Expand Down

0 comments on commit b910ab2

Please sign in to comment.