On 05/15/2017 08:53 AM, Zsolt Ero wrote:
Right now, the documentation for session.refresh() mentions:
lockmode – Passed to the Query
<http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query>
as used by with_lockmode()
<http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode>.
Where clicking on with_lockmode() links to the following note:
Deprecated since version 0.9.0: superseded by Query.with_for_update()
<http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_for_update>.
My questions are:
1. How should I use refresh with specific update modes? Should I just
discard that depreciation note?
looking at the code, it seems like refresh() -> lockmode is still
feeding straight to the old query.with_lockmode() (this is surprising).
So w/ refresh, you should use those lockmode arguments, yes. The
newer with_for_update() separates things into the use of individual
flags, which is nice, but for session.refresh(), we'd need some way to
specify that bundle of flags.
This is definitely a bug that with_lockmode() is legacy but we forgot to
update refresh() so the issue is at
https://bitbucket.org/zzzeek/sqlalchemy/issues/3991/sessionrefresh-load_on_ident-still.
"lockmode" will continue to work however.
2. Are there plans to support all 4 update modes of recent PostgreSQL's?
https://www.postgresql.org/docs/9.6/static/explicit-locking.html
In which case, would it be simpler to just use the DB supplied names
instead of trying to encode and decode it into boolean parameters to a
general function? I find that the documentation of PostgreSQL's mode is
already quite complicated and definitely needs to be properly read by
anyone trying to use one, so trying to hide it behind a generic function
might just lead to confusion, in my opinion.
those modes are all supported by with_for_update(), that documentation
page served as the guide for when the feature was created. The reason
there are boolean flags is to support other databases besides Postgresql
as well as to provide a consistent place to provide for "OF", which
refrers to a SQL expression. The breakdown of how the flags translate
to MySQL, Oracle, and Postgresql is at
http://docs.sqlalchemy.org/en/latest/core/selectable.html#sqlalchemy.sql.expression.GenerativeSelect.with_for_update.
A table view of these settings would also be appropriate as an
addition to the documentation.
Why not just make those specific modes an imports like other specifics
already are.
from sqlalchemy.dialects.postgresql import lock_key_no_update
q = sess.query(User).with_for_update(lock_key_no_update)
and
session.refresh(instance, lockmode= lock_key_no_update))
Just my idea
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.