openpyxl.drawing.graphicGroupTransform2D fails on instantiate

Issue #976 resolved
Justin Frahm
created an issue

Instantiating a GroupTransform2D results in an exception:

from openpyxl.drawing.graphic import GroupTransform2D
gt = GroupTransform2D()

Python 3.6 stack trace:

Traceback (most recent call last):
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/descriptors/base.py", line 57, in _convert
    value = expected_type(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
 During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/drawing/graphic.py", line 53, in __init__
    self.rot = rot
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/descriptors/base.py", line 69, in __set__
    value = _convert(self.expected_type, value)
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/descriptors/base.py", line 59, in _convert
    raise TypeError('expected ' + str(expected_type))
TypeError: expected <class 'int'>

Python 2.7 stack trace:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/drawing/graphic.py", line 53, in __init__
    self.rot = rot
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/descriptors/base.py", line 69, in __set__
    value = _convert(self.expected_type, value)
  File "/home/jusdino/ownCloud/Documents/eclipse/openpyxl/openpyxl/descriptors/base.py", line 59, in _convert
    raise TypeError('expected ' + str(expected_type))
TypeError: expected <type 'long'>

This happens when using 2.5, 2.6, and Default branches.

Comments (11)

  1. CharlieC

    Thanks for the report.

    DrawingML is so extensive that it's only supported on a case by case basis. Initially enough to allow charts and images to be included in files. Unfortunately, in order to read charts we have to read a whole load of DrawingML which invariably relates in something breaking. Fixing stuff is normally a question of correcting the autogenerated classes and adding appropriate tests. However, because DrawingML is very abstract it's often quite hard to work stuff out without examples so a file would be much appreciated.

  2. Justin Frahm reporter

    Ok, I found a file I can share that produces this issue. I thought, from looking at the constructor, that GroupTransform2D was intended to be able to be instantiated without specifying rot but not doing so results in the above exceptions.

  3. Justin Frahm reporter

    I have no idea if this works with your intentions for these components but, I 'resolved' the exceptions by providing some more useful default values for the properties that aren't specified in the constructors in the case of the attached file:
    https://bitbucket.org/jusdino/openpyxl/commits/817ad9c7ca41c1fbd795d574508fb8aa0e84746d

    I think there is at least one more class that I saw default values that caused an error on construction - a class that had b and bold both as optional parameters but failed if neither was defined - Font maybe?

    Again, I don't really understand your intentions with the default values for parameters that appear to be required - I'm just trying to be helpful 😉

  4. CharlieC

    Thanks for the file. The classes were generated automatically from the XSD and are far from perfect but DrawingML is so extensive that I didn't have time to check everything and so they'll be corrected as and when.

    <xsd:complexType name="CT_GroupTransform2D">
    <xsd:sequence>
    <xsd:element name="off" type="CT_Point2D" minOccurs="0" maxOccurs="1"/> <xsd:element name="ext" type="CT_PositiveSize2D" minOccurs="0" maxOccurs="1"/> <xsd:element name="chOff" type="CT_Point2D" minOccurs="0" maxOccurs="1"/> <xsd:element name="chExt" type="CT_PositiveSize2D" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>  <xsd:attribute name="rot" type="ST_Angle" use="optional" default="0"/>
      <xsd:attribute name="flipH" type="xsd:boolean" use="optional" default="false"/>
      <xsd:attribute name="flipV" type="xsd:boolean" use="optional" default="false"/>
    </xsd:complexType>
    

    According to the spec rot can be None in which case it will be considered to be 0 but Excel might still complain. The spec is full of things like this, which is why the files are so important.

  5. Justin Frahm reporter

    Thanks for the explanation. It doesn't look like the above change resolves the issue with rot though. The attached workbook still throws the same exception when I try to load_workbook.

    Update
    Please excuse my slowness! I see what you did now and all is good!

    Thank you for your great work!

  6. Log in to comment