Apostrophes (') doubles itself when its used with name while querying products

Django Graphene doubles apostrophes when multiple queries are executed

I am using Django with Graphene and a custom CustomFilterConnectionField. When I execute a single GraphQL query, category names containing an apostrophe are returned correctly:

Chocolate's

However, when multiple queries are executed, the apostrophe is sometimes doubled:

Chocolate''s

My model is:

class Category(
    TimeStampWithCreatorModel,
    TimeFramedModel,
    StatusModel,
    SelfRelationModel,
    SoftDeletableModel
):
    def get_order_count(*args, **kwargs):
        order_count = Category.objects.filter(status='category').count() + 1
        return order_count

    CONDITIONS_LIST = (
        ('no_conditions', "No conditions"),
        ('select_one_modifier', "Select one modifier"),
        ('select_upto_two_modifiers', "Select upto two modifiers"),
        ('select_upto_three_modifiers', 'Select upto three modifiers'),
        ('select_upto_four_modifiers', 'Select upto four modifiers'),
        ('select_upto_five_modifiers', 'Select upto five modifiers')
    )

    STATUS = Choices('category', 'promotion', 'modifier')

    plu = models.CharField(null=True, blank=True, max_length=255)
    image = models.ImageField(null=True, blank=True, upload_to="category-image")
    is_visible = models.BooleanField(null=True, blank=True, default=True)
    display_in_website = models.BooleanField(null=True, blank=True, default=True)
    index = models.IntegerField(null=True, blank=True, default=get_order_count)
    display_image = models.BooleanField(default=True, null=True, blank=True)

    category_conditions = models.CharField(
        choices=CONDITIONS_LIST,
        default="no_conditions",
        max_length=255,
        blank=True,
        null=True
    )

    price_override = models.BooleanField(default=False)

My GraphQL query is:

class ProductQuery(graphene.ObjectType):
    category = relay.Node.Field(CategoryNode)
    categories = CustomFilterConnectionField(CategoryNode)

And my CategoryNode is:

class CategoryNode(SimplePOSObjectType, DjangoObjectType):
    total_items = graphene.String()
    category_conditions = graphene.String()

    class Meta:
        model = Category
        filter_fields = {
            'level': ['exact'],
            'name': ['icontains'],
            'parent': ['exact'],
            'status': ['exact'],
            'display_in_website': ['exact'],
        }
        interfaces = (relay.Node,)
        connection_class = ExtendedConnection

For example, the database contains:

Chocolate's

but after executing multiple GraphQL queries I get:

Chocolate''s

I am not modifying the name field in the model.

Has anyone encountered this issue with Django Graphene? Could this be caused by the custom CustomFilterConnectionField, SimplePOSObjectType, or ExtendedConnection?

What would be the correct way to prevent the apostrophe from being escaped/mutated multiple times?

Вернуться на верх