Skip to content
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

Documentation bug on queries.rst #1152

Closed
richard-to opened this issue Dec 29, 2022 · 1 comment
Closed

Documentation bug on queries.rst #1152

richard-to opened this issue Dec 29, 2022 · 1 comment
Labels

Comments

@richard-to
Copy link

On this page https://flask-sqlalchemy.palletsprojects.com/en/3.0.x/queries/#select, the information for querying one object is slightly incorrect.

user = db.session.execute(db.select(User).filter_by(username=username)).one()

This yields something like:

(<User 1>,)

I believe this is because we are working with the ORM models, so we need to use ScalarResult instead of Result. See https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.ScalarResult

So I think the example should read:

user = db.session.execute(db.select(User).filter_by(username=username)).scalars().one()

This will yield the model with out the tuple.

<User 1>

Environment:

  • Python version: 3.11.0
  • Flask-SQLAlchemy version: 3.0.2
  • SQLAlchemy version: 1.4.44

I'm happy to update the documentation. I was considering sending a pull request, but it's late, so ended up filing a bug instead.

@davidism davidism added the docs label Jan 9, 2023
@davidism
Copy link
Member

davidism commented Jan 9, 2023

b48c2da

@davidism davidism closed this as completed Jan 9, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants