Skip to content

AttributeError: 'XXXXX' object has no attribute 'YYYYY' only in aws lambda function #332

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

Open
8 tasks done
ivanyschen opened this issue May 6, 2022 · 2 comments
Open
8 tasks done
Labels
question Further information is requested

Comments

@ivanyschen
Copy link

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

class CoursePostgresORM(SQLModel, table=True):
    __tablename__ = 'courses'
    __table_args__ = {'schema': 'course_catalog', }
    id_: str = Field(alias='id', sa_column=Column('id', primary_key=True))

    regions: List['CourseRegionLinkPostgresORM'] = Relationship(back_populates='course')
    
class RegionPostgresORM(SQLModel, table=True):
    __tablename__ = 'regions'
    __table_args__ = {'schema': 'public', }
    id_: int = Field(sa_column=Column('id', primary_key=True))

    courses: List['CourseRegionLinkPostgresORM'] = Relationship(back_populates='region')

class CourseRegionLinkPostgresORM(SQLModel, table=True):
    __tablename__ = 'courses_regions'
    __table_args__ = {'schema': 'course_catalog', }
    course_id: str = Field(foreign_key='course_catalog.courses.id', primary_key=True)
    region_id: int = Field(foreign_key='public.regions.id', primary_key=True)
    modified_at: datetime
    created_at: datetime

    course: 'CoursePostgresORM' = Relationship(back_populates='regions')
    region: 'RegionPostgresORM' = Relationship(back_populates='courses')


def lambda_handler(event, context):
    """
    This LF responsible for syncing joint tables.
    """
    LOGGER.info(msg='Updating course-region table...')
    with Session(POSTGRES) as session:
        results = session.exec(select(CourseRegionLinkPostgresORM))
        first_row = results.fetchall()[0]
        print(first_row.region)

Description

I encountered some issue where I was thrown with AttributeError: 'XXXXX' object has no attribute 'YYYYY' while trying to access an Relationship attribute of a model in aws lambda function. I was able to run the above code fine on my local but it would produced the following error in an AWS lambda function.
AttributeError: 'CourseRegionLinkPostgresORM' object has no attribute 'region'. Any thoughts are welcome. I've got stuck for the whole day. Thanks!

Operating System

Other

Operating System Details

AWS lambda function

SQLModel Version

0.0.6

Python Version

3.7

Additional Context

No response

@ivanyschen ivanyschen added the question Further information is requested label May 6, 2022
@byrman
Copy link
Contributor

byrman commented May 6, 2022

What version of SQLAlchemy is being used in AWS Lambda? Perhaps you bumped into #315?

@ivanyschen
Copy link
Author

What version of SQLAlchemy is being used in AWS Lambda? Perhaps you bumped into #315?

@byrman , thanks for pointing me to it! By pinning my sqlalchemy to .34, the code works fine again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants