Skip to content

Commit e911379

Browse files
committed
Run formatter and linter
1 parent 7e0aa2c commit e911379

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

strawberry_django/optimizer.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,15 +707,13 @@ def _must_use_prefetch_related(
707707
model_field: models.ForeignKey | OneToOneRel,
708708
) -> bool:
709709
f_type = _get_django_type(field)
710-
if f_type and hasattr(f_type, "get_queryset"):
711-
# If the field has a get_queryset method, change strategy to Prefetch
712-
# so it will be respected
713-
return True
714-
if is_polymorphic_model(model_field.related_model):
715-
# If the model is using django-polymorphic, change strategy to Prefetch,
716-
# so its custom queryset will be used, returning polymorphic models
717-
return True
718-
return False
710+
711+
# - If the field has a get_queryset method, use Prefetch so it will be respected
712+
# - If the model is using django-polymorphic,
713+
# use Prefetch so its custom queryset will be used, returning polymorphic models
714+
return (f_type and hasattr(f_type, "get_queryset")) or is_polymorphic_model(
715+
model_field.related_model
716+
)
719717

720718

721719
def _get_hints_from_django_foreign_key(

tests/polymorphism_custom/models.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33

44
class Company(models.Model):
55
name = models.CharField(max_length=100)
6-
main_project = models.ForeignKey('CustomPolyProject', null=True, blank=True, on_delete=models.CASCADE)
6+
main_project = models.ForeignKey(
7+
"CustomPolyProject", null=True, blank=True, on_delete=models.CASCADE
8+
)
79

810
class Meta:
9-
ordering = ('name',)
11+
ordering = ("name",)
1012

1113

1214
class CustomPolyProject(models.Model):
13-
company = models.ForeignKey(Company, null=True, blank=True, on_delete=models.CASCADE, related_name='projects')
15+
company = models.ForeignKey(
16+
Company,
17+
null=True,
18+
blank=True,
19+
on_delete=models.CASCADE,
20+
related_name="projects",
21+
)
1422
topic = models.CharField(max_length=30)
1523
artist = models.CharField(max_length=30, blank=True)
1624
supervisor = models.CharField(max_length=30, blank=True)

tests/polymorphism_custom/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from strawberry_django.pagination import OffsetPaginated
99
from strawberry_django.relay import ListConnectionWithTotalCount
1010

11-
from .models import CustomPolyProject, Company
11+
from .models import Company, CustomPolyProject
1212

1313

1414
@strawberry_django.interface(CustomPolyProject)

tests/polymorphism_custom/test_optimizer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from tests.utils import assert_num_queries
66

7-
from .models import CustomPolyProject, Company
7+
from .models import Company, CustomPolyProject
88
from .schema import schema
99

1010

@@ -257,7 +257,7 @@ def test_polymorphic_relation():
257257
"topic": rp.topic,
258258
"supervisor": rp.supervisor,
259259
},
260-
}
260+
},
261261
]
262262
}
263263

@@ -266,7 +266,9 @@ def test_polymorphic_relation():
266266
def test_polymorphic_nested_list():
267267
company = Company.objects.create(name="Company")
268268
ap = CustomPolyProject.objects.create(company=company, topic="Art", artist="Artist")
269-
rp = CustomPolyProject.objects.create(company=company, topic="Research", supervisor="Supervisor")
269+
rp = CustomPolyProject.objects.create(
270+
company=company, topic="Research", supervisor="Supervisor"
271+
)
270272

271273
query = """\
272274
query {

0 commit comments

Comments
 (0)