Skip to content

Commit 098cead

Browse files
committed
Cleaning up code and add changelog
1 parent 2656d00 commit 098cead

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ any parts of the framework not mentioned in the documentation should generally b
1313
### Fixed
1414

1515
* Fixed invalid relationship pointer in error objects when field naming formatting is used.
16+
* Properly resolved related resource type when nested source field is defined.
1617

1718
## [5.0.0] - 2022-01-03
1819

tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ForeignKeySource(DJAModel):
4141
)
4242

4343

44-
class NestedRelationshipSource(DJAModel):
44+
class NestedRelatedSource(DJAModel):
4545
m2m_source = models.ManyToManyField(ManyToManySource, related_name="nested_source")
4646
fk_source = models.ForeignKey(
4747
ForeignKeySource, related_name="nested_source", on_delete=models.CASCADE

tests/test_utils.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ForeignKeyTarget,
2626
ManyToManySource,
2727
ManyToManyTarget,
28-
NestedRelationshipSource,
28+
NestedRelatedSource,
2929
)
3030
from tests.serializers import BasicModelSerializer
3131

@@ -315,48 +315,44 @@ class Meta:
315315

316316

317317
@pytest.mark.parametrize(
318-
"model_class,field,output,related_field_kwargs",
318+
"field,output,related_field_kwargs",
319319
[
320320
(
321-
NestedRelationshipSource,
322321
"m2m_source.targets",
323322
"ManyToManyTarget",
324323
{"many": True, "queryset": ManyToManyTarget.objects.all()},
325324
),
326325
(
327-
NestedRelationshipSource,
328326
"m2m_target.sources.",
329327
"ManyToManySource",
330328
{"many": True, "queryset": ManyToManySource.objects.all()},
331329
),
332330
(
333-
NestedRelationshipSource,
334331
"fk_source.target",
335332
"ForeignKeyTarget",
336333
{"many": True, "queryset": ForeignKeyTarget.objects.all()},
337334
),
338335
(
339-
NestedRelationshipSource,
340336
"fk_target.source",
341337
"ForeignKeySource",
342338
{"many": True, "queryset": ForeignKeySource.objects.all()},
343339
),
344340
],
345341
)
346-
def test_get_related_resource_type_nested_source(
347-
model_class, field, output, related_field_kwargs
342+
def test_get_related_resource_type_from_nested_source(
343+
db, field, output, related_field_kwargs
348344
):
349345
class RelatedResourceTypeSerializer(serializers.ModelSerializer):
350-
relationship = serializers.ResourceRelatedField(
346+
relation = serializers.ResourceRelatedField(
351347
source=field, **related_field_kwargs
352348
)
353349

354350
class Meta:
355-
model = model_class
356-
fields = ("relationship",)
351+
model = NestedRelatedSource
352+
fields = ("relation",)
357353

358354
serializer = RelatedResourceTypeSerializer()
359-
field = serializer.fields["relationship"]
355+
field = serializer.fields["relation"]
360356
assert get_related_resource_type(field) == output
361357

362358

0 commit comments

Comments
 (0)