Skip to content

Setting values in association proxies breaks as of 1.3.1 #4573

Closed
@Paradoxis

Description

@Paradoxis

After upgrading SqlAlchemy from 1.2.18 to 1.3.1 my unit tests fail with the following stack trace:

Error
Traceback (most recent call last):
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 245, in _as_instance
    inst = class_.__dict__[self.key + "_inst"]
KeyError: '_AssociationProxy__columns_4746492392_inst'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 601, in run
    self.setUp()
  File "/Users/luke/Documents/Projects/my-project/tests/reports.py", line 49, in setUp
    ['3/1/18', 5, 6]
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 202, in __set__
    return self._as_instance(class_, obj).set(obj, values)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 567, in set
    proxy._bulk_replace(self, values)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 967, in _bulk_replace
    assoc_proxy._set(self, values)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 631, in _set
    proxy.extend(values)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 1067, in extend
    self.append(v)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 1052, in append
    item = self._create(value)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 974, in _create
    return self.creator(value)
  File "<string>", line 4, in __init__
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 441, in _initialize_instance
    manager.dispatch.init_failure(self, args, kwargs)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 129, in reraise
    raise value
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 438, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "/Users/luke/Documents/Projects/my-project/my/project/models/datatablerow.py", line 16, in __init__
    self._proxied = values
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 202, in __set__
    return self._as_instance(class_, obj).set(obj, values)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 249, in _as_instance
    inst = AssociationProxyInstance.for_proxy(self, owner, obj)
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 375, in for_proxy
    target_assoc, parent, owning_class, target_class, value_attr
  File "/Users/luke/Documents/Projects/my-project/venv/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 388, in _construct_for_assoc
    if attr._is_internal_proxy and not hasattr(attr, "impl"):
AttributeError: 'property' object has no attribute '_is_internal_proxy'

The issue appears to happen when setting values on an association proxy inside of a polymorphic table (I sadly can't show the exact code to replicate this due to privacy reasons)

Activity

zzzeek

zzzeek commented on Mar 26, 2019

@zzzeek
Member

hi there -

Perhaps you mean to use a @hybrid_property? @property is not really supported with association proxies nor is it necessary.

zzzeek

zzzeek commented on Mar 26, 2019

@zzzeek
Member

ignore my last comment, it was meant for a similar issue. deleting it now

zzzeek

zzzeek commented on Mar 26, 2019

@zzzeek
Member

OK, turns out the same fix in #4574 allows the setter to work here, we'll just do that

added
bugSomething isn't working
duplicateThis issue or pull request already exists
sqlalchemy.extextension modules, most of which are ORM related
on Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existsormsqlalchemy.extextension modules, most of which are ORM related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zzzeek@Paradoxis

        Issue actions

          Setting values in association proxies breaks as of 1.3.1 · Issue #4573 · sqlalchemy/sqlalchemy