mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-13 05:34:20 +03:00
fix: revert PR-1380
This commit is contained in:
parent
34cef2bccd
commit
047810fe9a
|
@ -1073,6 +1073,9 @@ def test_proxy_model_support():
|
|||
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.
|
||||
|
|
|
@ -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, [])
|
||||
|
|
|
@ -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 name, attr in model.__dict__.items():
|
||||
# Don't duplicate any local fields
|
||||
if name in local_field_names:
|
||||
continue
|
||||
|
||||
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)
|
||||
# "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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user