- SQLAlchemy Version: 2.0
- Database Backend: Postgres 16.2
Below is a sample code of my entities and operation:
class Status(enum.Enum): COMPLETED = "completed" PENDING = "pending" IN_QUEUE = "in_queue" CANCELLED = "cancelled" ERROR = "error" class Entity1(Base): pk : Mapped[int] = mapped_column(Integer, autoincrement = True, primary_key = True) sys_value: Mapped[str] = mapped_column(String(100), nullable = False, unique = True) status : Mapped[Status] = mapped_column(sqlalchemy.Enum(Status), nullable = False) class Entity2(Base): #... More columns sys_value : Mapped[str] = mapped_column(String(100), nullable = True) # .. More columns query = select(Entity2.sys_value).where(...).distinct(Entity2.sys_value) insert_query = insert(Entity1).select_from([Entity1.sys_value, Entity1.status] , select(query.subquery().c.sys_value, literal(Status.PENDING))).on_conflict_do_update() async with get_session() as session: session.execute(insert_query)
Error received:
sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.InvalidTextRepresentationError'>: invalid input value for enum status: "pending"
I do not know why the enum value says its incorrect. I checked postgres through PgAdmin4, and the value pending
does exist.
submitted by /u/PerpetualSanaSimp
[link] [comments]
r/learnpython SQLAlchemy Version: 2.0 Database Backend: Postgres 16.2 Below is a sample code of my entities and operation: class Status(enum.Enum): COMPLETED = “completed” PENDING = “pending” IN_QUEUE = “in_queue” CANCELLED = “cancelled” ERROR = “error” class Entity1(Base): pk : Mapped[int] = mapped_column(Integer, autoincrement = True, primary_key = True) sys_value: Mapped[str] = mapped_column(String(100), nullable = False, unique = True) status : Mapped[Status] = mapped_column(sqlalchemy.Enum(Status), nullable = False) class Entity2(Base): #… More columns sys_value : Mapped[str] = mapped_column(String(100), nullable = True) # .. More columns query = select(Entity2.sys_value).where(…).distinct(Entity2.sys_value) insert_query = insert(Entity1).select_from([Entity1.sys_value, Entity1.status] , select(query.subquery().c.sys_value, literal(Status.PENDING))).on_conflict_do_update() async with get_session() as session: session.execute(insert_query) Error received: sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class ‘asyncpg.exceptions.InvalidTextRepresentationError’>: invalid input value for enum status: “pending” I do not know why the enum value says its incorrect. I checked postgres through PgAdmin4, and the value pending does exist. submitted by /u/PerpetualSanaSimp [link] [comments]
- SQLAlchemy Version: 2.0
- Database Backend: Postgres 16.2
Below is a sample code of my entities and operation:
class Status(enum.Enum): COMPLETED = "completed" PENDING = "pending" IN_QUEUE = "in_queue" CANCELLED = "cancelled" ERROR = "error" class Entity1(Base): pk : Mapped[int] = mapped_column(Integer, autoincrement = True, primary_key = True) sys_value: Mapped[str] = mapped_column(String(100), nullable = False, unique = True) status : Mapped[Status] = mapped_column(sqlalchemy.Enum(Status), nullable = False) class Entity2(Base): #... More columns sys_value : Mapped[str] = mapped_column(String(100), nullable = True) # .. More columns query = select(Entity2.sys_value).where(...).distinct(Entity2.sys_value) insert_query = insert(Entity1).select_from([Entity1.sys_value, Entity1.status] , select(query.subquery().c.sys_value, literal(Status.PENDING))).on_conflict_do_update() async with get_session() as session: session.execute(insert_query)
Error received:
sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.InvalidTextRepresentationError'>: invalid input value for enum status: "pending"
I do not know why the enum value says its incorrect. I checked postgres through PgAdmin4, and the value pending
does exist.
submitted by /u/PerpetualSanaSimp
[link] [comments]