session.merge sqlalchemy

stmt = (
    select(User).
    where(User.name.in_(names)).
    execution_options(populate_existing=True).
    options(selectinload(User.addresses)
)
# will refresh all matching User objects as well as the related
# Address objects
users = session.execute(stmt).scalars().all()
Blue-eyed Boar