question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
Msordetcommented, 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. 😃

2reactions
jbvsmocommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use UUIDs in SQLAlchemy? - Stack Overflow
The sqlalchemy postgres dialect supports UUID columns. This is easy (and the question is specifically postgres) -- I don't understand why ...
Read more >
PostgreSQL - SQLAlchemy 1.4 Documentation
When SQLAlchemy issues a single INSERT statement, to fulfill the contract of having the “last insert identifier” available, a RETURNING clause is added...
Read more >
Error Messages - SQLAlchemy 1.4 Documentation
Object cannot be converted to 'persistent' state, as this identity map is no longer valid. AsyncIO Exceptions. AwaitRequired; MissingGreenlet; No Inspection ...
Read more >
What's New in SQLAlchemy 1.1?
JSON Columns will not insert JSON NULL if no value is supplied and no default is ... Same-named @validates decorators will now raise...
Read more >
Default behavior for sqlalchemy_utils.UUIDType
id = Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4) ... don't know what the 'binary' flag on the sqlalchemy_utils version does):
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found