[Python] sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped entity expected

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am running into this sqlachemy error that I haven't been able to understand:

    sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped entity expected - got '<class '__main__.JobRecord'>'


    What does this error mean? What are possible causes?

    This is the method that triggers the error:

    @classmethod
    def find_job_record_from_pk(cls, pk):
    '''
    return the job record with the given pk
    '''
    job_record = MlcDb.get_session().query(cls).filter(cls.pk == pk).first()
    return job_record


    Mapping:

    @classmethod
    def define_mapping(cls):
    '''
    SQLAlchemy mapping definition
    '''
    cls.mapper = mapper(cls, cls.table,
    polymorphic_on = cls.table.c.item_type,
    properties = {
    'item_type': synonym('_JobRecord__item_type', map_column=True),
    'version': synonym('_JobRecord__version', map_column=True),
    'state': synonym('_JobRecord__state', map_column=True),
    'date_created' : synonym( '_JobRecord__date_created', map_column=True)
    }
    )

    Continue reading...

Compartilhe esta Página