Skip to content

Exception: Don't know how to convert the SQLAlchemy field: UUIDType #257

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
Msordet opened this issue Dec 17, 2019 · 6 comments
Closed

Exception: Don't know how to convert the SQLAlchemy field: UUIDType #257

Msordet opened this issue Dec 17, 2019 · 6 comments

Comments

@Msordet
Copy link

Msordet commented Dec 17, 2019

Hi,

My app crashes with the following mapping:

#error
Exception: Don't know how to convert the SQLAlchemy field item.uuid_column (<class 'sqlalchemy.sql.schema.Column'>)

# model
from sqlalchemy_utils import UUIDType

class Item(Base):
    uuid_column = Column(UUIDType(binary=False), nullable=False, unique=True)

# schema
from graphene_sqlalchemy import SQLAlchemyObjectType

class ItemNode(SQLAlchemyObjectType):
    class Meta:
        model = Item

I tried to put this in my schema file to no avail:

from sqlalchemy_utils import UUIDType
from graphene_sqlalchemy.converter import get_column_doc, is_column_nullable, convert_sqlalchemy_type

@convert_sqlalchemy_type.register(UUIDType)
def convert_column_to_string(type, column, registry=None):
    return graphene.String(description=get_column_doc(column), required=not (is_column_nullable(column)))

I checked the following issues/PR but I don't get it: :/

Can someone point me in the right direction with this?

@Msordet
Copy link
Author

Msordet commented Dec 19, 2019

I found a solution by putting the convert_column_to_string right after the model declaration instead of in the schema file.
I don't really get why so if someone could explain, that'd be nice. :)

@Msordet Msordet closed this as completed Dec 19, 2019
@jbvsmo
Copy link

jbvsmo commented Feb 22, 2021

This still doesn't work for me with the error:

Exception: NonNull could not have a mounted String() as inner type. Try with NonNull(String).

Trying with NonNull(String) give another error

AssertionError: Can only create NonNull of a Nullable GraphQLType

@jbvsmo
Copy link

jbvsmo commented Feb 23, 2021

The above error happens when I set primary_key=True on the column.
I don't see why an UUID could not be the primary_key, but seems like this is an issue with graphene-sqlalchemy treating as string, since the model works fine

uuid = Column(UUIDType, primary_key=True)

@calibodhi
Copy link

Any updates on this issue? I am trying to use a UUID as a primary key and having the same error as the original above. Many thanks 🙏

@rrobby86
Copy link

rrobby86 commented Nov 29, 2022

Using this custom SQLAlchemy type using UUID objects on Python side, on graphene 3.1.1 and graphene-sqlalchemy 3.0.0b3 (other versions may differ) I managed to get proper conversion to string without errors adding the following code before declaration of GraphQL schema (i.e. SQLAlchemyObjectType subclasses):

from graphene_sqlalchemy.converter import convert_sqlalchemy_type
from my.own.sub.package import GUID

@convert_sqlalchemy_type.register(GUID)
def convert_uuid_to_string(type, column, registry=None):
    return String

Using String(description=..., required=...) as suggested above was giving me an error NonNull could not have a mounted String() as inner type. Try with NonNull(String).

@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 May 29, 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

4 participants