RecursionError: maximum recursion depth exceeded
- Dominant language
- Python
- Stars
- 951
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
I'm generating svg images in a python code that I want to convert into png, but it fails. I could pinpoint that the problem is because of the use of the 'defs', 'g' and 'use' tags. I'm not sure if these tags are supported or something else goes wrong.
I have the following code:
```python
svg_string = """"""
cairosvg.svg2png(svg_string, write_to='test.png')
```
The output:
```python
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
in ()
----> 1 cairosvg.svg2png(svg_string, write_to='test.png')
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/__init__.py in (*args, **kwargs)
43 # Two lambdas needed for the closure
44 lambda surface_type: lambda *args, **kwargs:
---> 45 surface_type.convert(*args, **kwargs))(_surface_type)
46 _name = 'svg2{}'.format(_output_format.lower())
47 _function.__name__ = _name
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/surface.py in convert(cls, bytestring, **kwargs)
136 output = write_to or io.BytesIO()
137 instance = cls(
--> 138 tree, output, dpi, None, parent_width, parent_height, scale)
139 instance.finish()
140 if write_to is None:
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/surface.py in __init__(self, tree, output, dpi, parent_surface, parent_width, parent_height, scale)
193 width, height, viewbox, scale, preserved_ratio(tree))
194 self.context.move_to(0, 0)
--> 195 self.draw(tree)
196
197 @property
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
411 if display and node.tag not in INVISIBLE_TAGS:
412 for child in node.children:
--> 413 self.draw(child)
414
415 # Apply filter, mask and opacity
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
351 if node.tag in TAGS:
352 try:
--> 353 TAGS[node.tag](self, node)
354 except PointError:
355 # Error in point parsing, do nothing
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/defs.py in use(surface, node)
376 tree['width'], tree['height'] = node['width'], node['height']
377
--> 378 surface.draw(tree)
379 node.get('fill', None)
380 node.get('stroke', None)
... last 3 frames repeated, from the frame below ...
/Users/ds26/anaconda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
411 if display and node.tag not in INVISIBLE_TAGS:
412 for child in node.children:
--> 413 self.draw(child)
414
415 # Apply filter, mask and opacity
RecursionError: maximum recursion depth exceeded
```
If I save it into the an svg file, all the browsers can plot it properly. Cairosvg works fine on svg strings that don't have defs and use tags. Do you have any idea how I could tackle this issue? It would be quite important to use these tags...
python version: 3.6.0
OS: OSX 10.12.6
cairosvg: 2.1.2
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the provided SVG with cairosvg.svg2png, then inspect defs.py's use handler and surface.py's draw path shown in the traceback. The fix is complete when the defs/g/use example converts to test.png without RecursionError and existing behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100