← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1355939] Re: [Django 1.7] horizon table summation can raise TypeError

 

** Changed in: horizon
       Status: Fix Committed => Fix Released

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

Title:
  [Django 1.7] horizon table summation can raise TypeError

Status in OpenStack Dashboard (Horizon):
  Fix Released

Bug description:
  https://review.openstack.org/#/c/111932/

  With Django 1.7, the unit tests fail with the following error.
  It is one of work towards django 1.7.

  "average": lambda data: sum(data, 0.0) / len(data)

  TypeError: unsupported operand type(s) for +: 'float' and 'str'

  With Django 1.6, the template code that looked up the variable behind
  get_summation was catching the TypeError exception:

      try: # method call (assuming no args required)
          current = current()
      except TypeError: # arguments *were* required
          # GOTCHA: This will also catch any TypeError
          # raised in the function itself.
          current = settings.TEMPLATE_STRING_IF_INVALID  # invalid

  With Django 1.7, the code has been refined to catch the exception only
  when the function really requires argument (which get_summation()
  doesn't):

      try:  # method call (assuming no args required)
          current = current()
      except TypeError:
          try:
              getcallargs(current)
          except TypeError:  # arguments *were* required
              current = settings.TEMPLATE_STRING_IF_INVALID  # invalid
          else:
              raise

  Note that we need to install Django 1.7rc2 to reproduce this.
  So instead of blindly relying on sum(), I introduced a safe_sum() and
  safe_average() functions which mimick the behaviour we got with Django
  1.6 by returning an empty string when we have invalid input data.

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


References