Public bug reported:

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

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.

** Affects: horizon
     Importance: Undecided
         Status: New


** Tags: django1.7

-- 
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):
  New

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

  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

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