class BaseModel(models.Model):
creation_user = models.ForeignKey("User", related_name="+", on_delete=models.CASCADE)
class Meta:
abstract = True
class Pizza(BaseModel):
title = models.CharField(max_length=20)
class Order(BaseModel):
notes = models.CharField(max_length=20)
And the fields:
@strawberry.django.interface(models.BaseModel)
class BaseRecord:
created_by: "User" = field(select_related=['creation_user'])
@strawberry.django.field(models.Pizza)
class Pizza(BaseRecord, relay.Node):
name: str
@strawberry.django.field(models.Order)
class Order(BaseRecord, relay.Node):
notes: str
Where the first implementation (Pizza) would get the created_by field defined, and origin_django_type set.
When the next implementation (Order) tries to get the created_by field defined, it does but as the field has defined origin_django_type, it tried to recreate the field (else clause) and ignore all the hints.
System Information
strawberry-graphql-django: 0.23.0
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
We receive the funding once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
Describe the Bug
Note: all the following is pseudo code.
Given the following models:
And the fields:
When querying pizza objects like so:
Optimization hints are applied (
select_related
).But when querying order objects like so:
Optimization hints are not applied.
After debugging, it seems an issue around these lines: https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/strawberry_django/type.py#L350-L366
Where the first implementation (
Pizza
) would get thecreated_by
field defined, andorigin_django_type
set. When the next implementation (Order
) tries to get thecreated_by
field defined, it does but as the field has definedorigin_django_type
, it tried to recreate the field (else clause) and ignore all the hints.System Information
Upvote & Fund