← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1328387] [NEW] Instance object String field coercion of bool value is surprising

 

Public bug reported:

So in the process of converting certain test case from using an instance
dict to a fake instance object, I noticed the following:

self.instance_object.config_drive = False
self.assertFalse(self.instance_object.config_drive) # <<<< Fails

The reason the config_drive attribute is exhibiting this behavior is because it is actually declared as a String in the schema
(see related bug: https://bugs.launchpad.net/nova/+bug/1193438), and assignment of a bool value to it results in coercion to u'False' which evaluates to True in the boolean context.

While this issue can easily be worked around in the config drive unit
test (or with some conversion in the configdrive module where the
attribute is used), it would be less surprising in general for a bool
False value to be coerced to a string that once again evaluates to
False.

** Affects: nova
     Importance: Undecided
     Assignee: Vui Lam (vui)
         Status: New

** Description changed:

  So in the process of converting certain test case from using an instance
  dict to a fake instance object, I noticed the following:
  
  self.instance_object.config_drive = False
  self.assertFalse(self.instance_object.config_drive) # <<<< Fails
  
  The reason the config_drive attribute is exhibiting this behavior is because it is actually declared as a String in the schema
  (see related bug: https://bugs.launchpad.net/nova/+bug/1193438), and assignment of a bool value to it results in coercion to u'False' which evaluates to True in the boolean context.
  
  While this issue can easily be worked around in the config drive unit
  test (or with some conversion in the configdrive module where the
- attribute is used), it would be less surprising in generate for a bool
- False be coerce to a string that evaluates to False instead.
+ attribute is used), it would be less surprising in general for a bool
+ False value to be coerced to a string that once again evaluates to
+ False.

-- 
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/1328387

Title:
  Instance object String field coercion of bool value is surprising

Status in OpenStack Compute (Nova):
  New

Bug description:
  So in the process of converting certain test case from using an
  instance dict to a fake instance object, I noticed the following:

  self.instance_object.config_drive = False
  self.assertFalse(self.instance_object.config_drive) # <<<< Fails

  The reason the config_drive attribute is exhibiting this behavior is because it is actually declared as a String in the schema
  (see related bug: https://bugs.launchpad.net/nova/+bug/1193438), and assignment of a bool value to it results in coercion to u'False' which evaluates to True in the boolean context.

  While this issue can easily be worked around in the config drive unit
  test (or with some conversion in the configdrive module where the
  attribute is used), it would be less surprising in general for a bool
  False value to be coerced to a string that once again evaluates to
  False.

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


Follow ups

References