Skip to content

Global ids from objects with composite primary keys are not correctly extracted #43

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

Closed
eoma opened this issue May 1, 2017 · 4 comments

Comments

@eoma
Copy link
Contributor

eoma commented May 1, 2017

Due to the way graphene-sqlalchemy constructs global ids, it is not possible to get unique global ids from objects with composite primary keys, typically association objects.

@eoma
Copy link
Contributor Author

eoma commented May 1, 2017

A serialization format of complex ids should probably be decided upon too, due to the way sqlalchemy's Query.get() expects ids to be entered.

@eoma
Copy link
Contributor Author

eoma commented May 1, 2017

A somewhat simple oneway solution is to make SQLAlchemyObjectType.resolve_id return a tuple of the primary keys if it is a list with more than one entry:

    def resolve_id(self, args, context, info):
        graphene_type = info.parent_type.graphene_type
        if is_node(graphene_type):
            keys = self.__mapper__.primary_key_from_instance(self)
            return tuple(keys) if len(keys) > 1 else keys[0]
        return getattr(self, graphene_type._meta.id, None)

@eoma eoma changed the title Global ids from objects with composite primary keys are not unique Global ids from objects with composite primary keys are not correctly extracted May 9, 2017
@syrusakbary
Copy link
Member

This is now merged, and also fixed in upcoming Graphene version 2.0

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants