Public bug reported:

In db.sqlalchemy.api.instance_get_all_by_filters() there is code that
looks like this:

if not filters.pop('soft_deleted', False):
    query_prefix = query_prefix.\
        filter(models.Instance.vm_state != vm_states.SOFT_DELETED)


In sqlalchemy a comparison against a non-null value will not match null values, 
so the above filter will not return objects where vm_state is NULL.

The problem is that in the Instance object the "vm_state" field is
declared as nullable.  In many cases "vm_state" will in fact have a
value, but in get_test_instance() in test/utils.py the value of
"vm_state" is not specified.

Given the above, it seems that either we need to configure
"models.Instance.vm_state" as not nullable (and deal with the fallout),
or else we need to update instance_get_all_by_filters() to explicitly
check for None--something like this perhaps:

if not filters.pop('soft_deleted', False):
    query_prefix = query_prefix.\
        filter(or_(models.Instance.vm_state != vm_states.SOFT_DELETED,
                   models.Instance.vm_state == None))

If we want to fix the query, I'll happily submit the updated code.

** Affects: nova
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1294756

Title:
  missing test for None in sqlalchemy query filter

Status in OpenStack Compute (Nova):
  New

Bug description:
  In db.sqlalchemy.api.instance_get_all_by_filters() there is code that
  looks like this:

  if not filters.pop('soft_deleted', False):
      query_prefix = query_prefix.\
          filter(models.Instance.vm_state != vm_states.SOFT_DELETED)

  
  In sqlalchemy a comparison against a non-null value will not match null 
values, so the above filter will not return objects where vm_state is NULL.

  The problem is that in the Instance object the "vm_state" field is
  declared as nullable.  In many cases "vm_state" will in fact have a
  value, but in get_test_instance() in test/utils.py the value of
  "vm_state" is not specified.

  Given the above, it seems that either we need to configure
  "models.Instance.vm_state" as not nullable (and deal with the
  fallout), or else we need to update instance_get_all_by_filters() to
  explicitly check for None--something like this perhaps:

  if not filters.pop('soft_deleted', False):
      query_prefix = query_prefix.\
          filter(or_(models.Instance.vm_state != vm_states.SOFT_DELETED,
                     models.Instance.vm_state == None))

  If we want to fix the query, I'll happily submit the updated code.

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1294756/+subscriptions

-- 
Mailing list: https://launchpad.net/~yahoo-eng-team
Post to     : yahoo-eng-team@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yahoo-eng-team
More help   : https://help.launchpad.net/ListHelp

Reply via email to