Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to address inheritance chain changes between Graphene 2 and 3? #1592

Open
simkessy opened this issue Feb 4, 2025 · 0 comments
Open

How to address inheritance chain changes between Graphene 2 and 3? #1592

simkessy opened this issue Feb 4, 2025 · 0 comments
Labels

Comments

@simkessy
Copy link

simkessy commented Feb 4, 2025

  • 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'>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant