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

many2one with reverse one2many to polymorphic Model #68

Open
gracinet opened this Issue Oct 25, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@gracinet
Copy link
Contributor

gracinet commented Oct 25, 2018

It seems that having a many2one with a reverse one2many towards a base polymorphic Model gives rise to problems upon deletions.

This is all happening in a change I'm trying to do within anyblok_wms_base (for its issue #26, with the m2o being from Avatar to Operation:

@register(Model.Wms.PhysObj)
class Avatar:
    (...)
    outcome_of = Many2One(index=True,
                          one2many='outcomes',
                          model=Model.Wms.Operation, nullable=False)

To reproduce, l

Traceback:

ERROR: test_whole_planned_execute_obliviate (anyblok_wms_base.core.operation.tests.test_move.TestMove)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok_wms_base/anyblok_wms_base/core/operation/tests/test_move.py", line 80, in test_whole_planned_execute_obliviate
    move.obliviate()
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok_wms_base/anyblok_wms_base/core/operation/base.py", line 559, in obliviate
    self.obliviate_single()
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok_wms_base/anyblok_wms_base/core/operation/base.py", line 743, in obliviate_single
    self.delete_outcomes()
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok_wms_base/anyblok_wms_base/core/operation/base.py", line 697, in delete_outcomes
    avatar.delete()
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok/anyblok/bloks/anyblok_core/core/sqlbase.py", line 577, in delete
    self.expire_relationship_mapped(mappers)
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok/anyblok/bloks/anyblok_core/core/sqlbase.py", line 531, in expire_relationship_mapped
    field.expire(*rfields)
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok/anyblok/bloks/anyblok_core/core/sqlbase.py", line 552, in expire
    self.registry.expire(self, fields)
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok/anyblok/registry.py", line 1093, in expire
    obj.__class__.get_hybrid_property_columns()
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok/anyblok/common.py", line 121, in wrapper
    return method(*args, **kwargs)
  File "/home/gracinet/anybox/projets/Sensee/anyblok_wms/anyblok/anyblok/bloks/anyblok_core/core/sqlbase.py", line 231, in get_hybrid_property_columns
    fd = cls.fields_description(*pks)
TypeError: fields_description() takes from 1 to 2 positional arguments but 3 were given

I checked with pdb:

-> fd = cls.fields_description(*pks)
(Pdb) l
226  	        inherited model if they come from polymorphisme
227  	        """
228  	        hybrid_property_columns = cls.hybrid_property_columns
229  	        if 'polymorphic_identity' in cls.__mapper_args__:
230  	            pks = cls.get_primary_keys()
231  ->	            fd = cls.fields_description(*pks)
232  	            for pk in pks:
233  	                if fd[pk].get('model'):
234  	                    Model = cls.registry.get(fd[pk]['model'])
235  	                    hybrid_property_columns.extend(
236  	                        Model.get_hybrid_property_columns())
(Pdb) pks
['id', 'id']

and I suspect these are the primary keys for the subclass (Move) as well as the polymorphic parent (Operation). Overall, I imagine theyre'd problems with m2os targetting Models with complex primary keyrs, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment