ModelBase._as_dict() makes assumptions about __dict__ that are changing

Bug #1830504 reported by Mike Bayer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.db
New
Undecided
Unassigned

Bug Description

in SQLAlchemy https://gerrit.sqlalchemy.org/#/c/sqlalchemy/sqlalchemy/+/1283/ the assumptions are changing when one does this:

    obj = SomeObject()
    print(obj.some_collection)

You'll still get the usual [] for `some_collection` or whatever it's supposed to be. But it's not going to be in `__dict__` until you mutate it, which is the same behavior as when you say "obj.some_column". You get None back but that's also not in `__dict__`.

Where this breaks is here:

https://github.com/openstack/oslo.db/blob/master/oslo_db/sqlalchemy/models.py#L98

which is because nova over here is relying upon the list being implicitly present in `__dict__` in these tests, specifically for the "rules" attribute:

https://github.com/openstack/nova/blob/master/nova/tests/unit/db/test_db_api.py#L1692

their comparison thing turns the object into dictionaries using _as_dict() here and expects the blank collection to be present, which is because they are implicitly setting it up here:

https://github.com/openstack/nova/blob/master/nova/db/sqlalchemy/api.py#L3862

now, the fix may be just for them to correctly say this instead:

    security_group_ref.rules = []

i might go that route instead...but...looking in `__dict__` is kind of weird here in general considering some things are loaded, some things not. I would think it would want to include relationships the same way it gets the columns, e.g. from the mapper.relationships, but I don't really know the assumptions being made here, and it's possible we just aren't going to know them anymore.

Revision history for this message
Mike Bayer (zzzeek) wrote :

Nova will probably be accepting my patch for this in https://review.opendev.org/#/c/661472/1 , I don't have plans to change oslo.db right now though I'm not super enthusiastic about how that function works.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.