[Sqlalchemy-tickets] Issue #3620: New query doesn't expire column_property with bindparam (zzzeek/s
Brought to you by:
zzzeek
|
From: Lukas S. <iss...@bi...> - 2015-12-28 23:42:33
|
New issue 3620: New query doesn't expire column_property with bindparam https://bitbucket.org/zzzeek/sqlalchemy/issues/3620/new-query-doesnt-expire-column_property Lukas Siemon: The column_property seems to be cached even when a new query is issued. Is doesn't matter if I use deferred or not. The expunge is obviously really ugly as a workaround. Is this something that could potentially be fixed or is there a better way of "flushing" the cache? We are using this pattern in many places in our application. However I only noticed today that the value gets cached. I would very much prefer a generic solution (i.e. where the model is declared and not where the query is generated). Test case: ``` #!python import unittest from sqlalchemy import (Column, Integer, String, select, bindparam) from sqlalchemy.orm import (column_property, undefer) from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy class TestDynamicBindparam(unittest.TestCase): def setUp(self): # -- create all the database models app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = ("sqlite://") db = SQLAlchemy(app) class Label(db.Model): __tablename__ = 'label' id = Column(Integer, primary_key=True, nullable=False) write_only = column_property( select(['-w-' == bindparam('perm', value=None, type_=String)]), deferred=True ) db.drop_all() db.create_all() self.Label = Label self.db = db def test_dynamic_bindparam(self): label = self.Label() self.db.session.add(label) self.db.session.commit() self.assertEqual(label.id, 1) self.assertIsNone(label.write_only) label = label.query.options( undefer(self.Label.write_only) ).params(perm='-w-').one() self.assertIsNone(label.write_only) # this should be True (!) self.db.session.expunge(label) label = label.query.options( undefer(self.Label.write_only) ).params(perm='-w-').one() self.assertTrue(label.write_only) label = label.query.options( undefer(self.Label.write_only) ).params(perm='---').one() self.assertTrue(label.write_only) # this should be False (!) ``` Responsible: zzzeek |