From 9b9b1f3e5b04c37f310595596b0447aa95f86539 Mon Sep 17 00:00:00 2001 From: M Aswin Kishore Date: Wed, 29 Nov 2023 10:22:29 +0530 Subject: [PATCH] fix: union type naming for mongo_fields having inner mongo_field eg: field_1 = ListField(GenericLazyReferenceField(choices=[X1,X2])) generates type ModelNoneUnionType This fix will make it ModelField1UnionType --- graphene_mongo/converter.py | 18 ++++++++++++++---- pyproject.toml | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/graphene_mongo/converter.py b/graphene_mongo/converter.py index f4cce42..5a6f37e 100644 --- a/graphene_mongo/converter.py +++ b/graphene_mongo/converter.py @@ -350,10 +350,20 @@ def convert_field_to_union(field, registry=None, executor: ExecutorEnum = Execut if len(_types) == 0: return None - name = ( - to_camel_case("{}_{}".format(field._owner_document.__name__, field.db_field)) + "UnionType" - if ExecutorEnum.SYNC - else "AsyncUnionType" + field_name = field.db_field + if field_name is None: + # Get db_field name from parent mongo_field + for db_field_name, _mongo_parent_field in field.owner_document._fields.items(): + if hasattr(_mongo_parent_field, "field") and _mongo_parent_field.field == field: + field_name = db_field_name + break + + name = to_camel_case( + "{}_{}_{}".format( + field._owner_document.__name__, + field_name, + "union_type" if executor == ExecutorEnum.SYNC else "async_union_type", + ) ) Meta = type("Meta", (object,), {"types": tuple(_types)}) _union = type(name, (graphene.Union,), {"Meta": Meta}) diff --git a/pyproject.toml b/pyproject.toml index 0bc3d0a..d2cebef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "graphene-mongo" packages = [{ include = "graphene_mongo" }] -version = "0.4.0" +version = "0.4.1" description = "Graphene Mongoengine integration" authors = [ "Abaw Chen ",