Open deepakunni3 opened 2 years ago
it seems to be an issue with dialect='postgresql+psycopg2'
E.g with 'postgresql+pygresql' I get:
from dataclasses import dataclass
from dataclasses import field
from typing import List
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import Text
from sqlalchemy import Integer
from sqlalchemy.orm import registry
from sqlalchemy.orm import relationship
mapper_registry = registry()
metadata = MetaData()
from test_schema import *
tbl_foo = Table('foo', metadata,
Column('prop1', Text, primary_key=True),
Column('prop2', Text, primary_key=True),
Column('prop3', Text, primary_key=True),
)
mapper_registry.map_imperatively(Foo, tbl_foo, properties={
})
my mistake.. all postgres dialects fail
mssql dialects succeed however...
OK, it's not in the sqla mapping logic itself,
it's this:
engine = create_mock_engine(
f'{self.dialect}://./MyDb',
strategy='mock',
executor= lambda sql, *multiparams, **params: print(f'{str(sql).rstrip()};'))
Yes, I did stumble upon that code block while debugging. It looks like the str(sql)
is raising an error when its called for an object that is an instance of _PGEnum
.
I wonder if this is an upstream (SQLAlchemy) bug or if we should be careful when we stringify the sql.
Is this still needed? If so, is @cmungall really the only person who can fix it?
I'm definitely not the only person who can do this!
The code Deepak highlights comes from the SQLA docs:
They show some different ways of doing this, also in the top answer here:
https://stackoverflow.com/questions/2128717/sqlalchemy-printing-raw-sql-from-create
If this issue persists then we file an upstream
Thank you @cmungall
Given that this ticket is 3 years old and there is no immediate use-case, perhaps we can close this ticket.
If it comes up again, we can reopen or create a new issue for tracking this.
When working with a model that has one (or more) enums defined:
Generation of SQLAlchemy classes for the
postgres:psycopg2
dialect via,Yields the following stacktrace,
Unsure if this has been observed before?
@hsolbrig @cmungall
Version of relevant dependencies,