traceback with dict-polymorphic example

14 views
Skip to first unread message

I Jenkins

unread,
Jul 14, 2021, 5:09:16 PM7/14/21
to sqlalchemy
Hi all,

Does anyone else have problems when trying to run the dictlike-polymorphic.py example?  With sqlalchemy 1.4.20 and python2.7 I'm getting this traceback:
```
2021-07-14 14:04:25,847 INFO sqlalchemy.engine.Engine INSERT INTO animal_fact (animal_id, "key", type, int_value, char_value, boolean_value) VALUES (?, ?, ?, ?, ?, ?)
2021-07-14 14:04:25,847 INFO sqlalchemy.engine.Engine [cached since 0.01913s ago] ((2, 'cuteness', 'integer', 5, None, None), (2, 'poisonous', 'boolean', None, None, 0), (2, 'weasel-like', 'boolean', None, None, 1), (3, 'cuteness', 'integer', 5, None, None), (3, 'poisonous', 'boolean', None, None, 1), (3, 'weasel-like', 'boolean', None, None, 0))
2021-07-14 14:04:25,848 INFO sqlalchemy.engine.Engine COMMIT
Traceback (most recent call last):
  File "dictlike-polymorphic.py", line 222, in <module>
    and_(AnimalFact.key == "weasel-like", AnimalFact.value == True)
  File "lib/python2.7/site-packages/sqlalchemy/sql/operators.py", line 360, in __eq__
    return self.operate(eq, other)
  File "lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 316, in operate
    return op(self.comparator, *other, **kwargs)
  File "dictlike-polymorphic.py", line 89, in __eq__
    return self._case() == cast(other, String)
  File "dictlike-polymorphic.py", line 86, in _case
    return case(whens, self.cls.type, null())
  File "<string>", line 2, in case
  File "lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 2838, in __init__
    for (c, r) in whens
ValueError: too many values to unpack
```
Thanks,
Ian

Mike Bayer

unread,
Jul 14, 2021, 11:00:08 PM7/14/21
to noreply-spamdigest via sqlalchemy
fixed in master, please apply this patch:

diff --git a/examples/vertical/dictlike-polymorphic.py b/examples/vertical/dictlike-polymorphic.py
index 23a6e093d9..4c81af6d54 100644
--- a/examples/vertical/dictlike-polymorphic.py
+++ b/examples/vertical/dictlike-polymorphic.py
@@ -83,7 +83,7 @@ class PolymorphicVerticalProperty(object):
                 for attribute, discriminator in pairs
                 if attribute is not None
             ]
-            return case(whens, self.cls.type, null())
+            return case(whens, value=self.cls.type, else_=null())

         def __eq__(self, other):
             return self._case() == cast(other, String)




--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
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+...@googlegroups.com.

I Jenkins

unread,
Jul 14, 2021, 11:21:53 PM7/14/21
to sqlalchemy

Awesome that seems to fix it. Thanks Mike!
Reply all
Reply to author
Forward
0 new messages