Skip to content
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

exception when overwriting columns with two levels of inheritance (3.1.0, 4.0.0a1) #149

Open
numberoverzero opened this issue Nov 13, 2021 · 1 comment
Assignees
Labels
Milestone

Comments

@numberoverzero
Copy link
Owner

reproducible on both 3.1.0 and 4.0.0a1 with:

#!/usr/bin/env python
from bloop import BaseModel, Column, Integer

class A(BaseModel):
    id_a = Column(Integer, hash_key=True)

class B(A):
    id_b = Column(Integer, hash_key=True)

# B still has a ref to B.id_a
assert all(x in dir(B) for x in {"id_a", "id_b"})
# note that this is the **actual parent id_a**  and not the copy that was temporarily
# created during BaseModel.__init_subclass__
assert B.id_a is A.id_a

# this will fail
class C(B):
    other_field = Column(Integer)

The grandparent is defined correctly, and the parent has the correct hash key (in Meta.keys, Meta.hash_key, Meta.projection, Meta.columns).

However, there are two problems:

  1. B.id_a still exists even though it's not actually a key on the model. This isn't the original parent value but a copy that was made, briefly bound during __init_subclass__ and then unbound.
  2. When the grandchild class C is being configured during BaseModel.__init_subclass__ the derived_attrs are defined as "all columns or indexes found with inspect.getmembers that are not also found in cls.__dict__" and this contains both the immediate parents' id_b as well as the grandparents' id_a. Since these are both hash keys, the derived_hash_keys check fails.
@numberoverzero numberoverzero self-assigned this Nov 13, 2021
@numberoverzero numberoverzero changed the title a second level of inheritance breaks when overwriting columns (3.1.0, 4.0.0a1) exception when overwriting columns with two levels of inheritance (3.1.0, 4.0.0a1) Nov 13, 2021
@numberoverzero
Copy link
Owner Author

error message for anyone searching:

bloop.exceptions.InvalidModel: The model C subclasses one or more models that declare multiple columns as the hash key: ['id_a', 'id_b']

@numberoverzero numberoverzero added this to the 4.0.0 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant