How to address inheritance chain changes between Graphene 2 and 3?
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- api, backend-api-design
Research direction
The issue names ObjectTypeWithID, ObjectTypeMeta, InterObjectType, and the differing Python MROs, but no repository files or tests. Start by reproducing the inheritance example on Graphene 2.x and 3.x, then inspect the generated MRO and constructor behavior. Done means the intended inheritance behavior is established and the issue has a documented or tested resolution.
Written by the indexing model from the issue text.
Description
- What is the current behavior?
In order for us to have consistent IDs and unique IDs for all our entities we made all entities were inheriting from this class:
class ObjectTypeWithID(ObjectType):
id = ID(required=True, description="globally unique identifier")
entity_id = String(required=True, description="identifier for the entity")
model_id = String(required=True, description="identifier for the entity model")
def __init__(self, id):
print('!!!ObjectTypeWithID.__init__')
self.id = generate_global_id(self.__class__.__name__, id)
self.entity_id = id
self.model_id = id
# usage
class User(ObjectTypeWithID)
def __init__:
super().__init__(user_id)
This worked fine in Graphene 2.x but once we tried to upgrade to Graphene 3.x it seems like super().__init__ does not trigger ObjectTypeWithID
I checked the mro and I noticed there's now InterObjectType between User and it's parent ObjectTypeWithID and I suspect it's getting in the way when call super()
user.__class__.__mro__ in Graphene 3.x
(
<User meta=<ObjectTypeOptions name='User'>>,
<class 'graphene.types.objecttype.ObjectTypeMeta.new.<locals>.InterObjectType'>,
<ObjectTypeWithID meta=<ObjectTypeOptions name='ObjectTypeWithID'>>,
<class 'graphene.types.objecttype.ObjectTypeMeta.new.<locals>.InterObjectType'>,
<ObjectType meta=None>,
<class 'graphene.types.objecttype.ObjectTypeMeta.new.<locals>.InterObjectType'>,
<BaseType meta=None>,
<SubclassWithMeta meta=None>, <class 'object'>
)
user.__class__.__mro__ in Graphene 2.x
(
<Campaign meta=<ObjectTypeOptions name='Campaign'>>,
<ObjectTypeWithID meta=<ObjectTypeOptions name='ObjectTypeWithID'>>,
<ObjectType meta=None>,
<BaseType meta=None>,
<SubclassWithMeta meta=None>,
<class 'object'>
)
- Dominant language
- Python
- Stars
- 8.2k
- Forks
- 818
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphene
-
Tutorial mistakes Open🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
graphql-python/graphene#1389 · 5 comments · 2 reactions ·
-
Python 3.14 support Open✨ enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
graphql-python/graphene#1601 · 2 comments ·
-
✨ enhancement
Difficulty 4/5 3-5 days Newbie friendliness 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
graphql-python/graphene#1593 ·
-
✨ enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
graphql-python/graphene#1577 ·
All issues in graphql-python/graphene
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100