wbond / pybars3

Handlebars.js template support for Python 3 and 2
GNU Lesser General Public License v3.0
179 stars 46 forks source link

AttributeError: 'list' object has no attribute 'grow' #27

Open mselevan opened 8 years ago

mselevan commented 8 years ago

I keep seeing this error during template compilation. Stack trace below

self._result.grow(u" result.append(%s)\n" % repr(value)): AttributeError: 'list' object has no attribute 'grow'
at add_literal (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pybars/_compiler.py:585)
at <module> (<string>:1)
at rule_literal (/pymeta_generated_code/pymeta_grammar__Grammar.py:148)
at _apply (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pymeta/runtime.py:329)
at _G_or_1 (/pymeta_generated_code/pymeta_grammar__Grammar.py:32)
at _or (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pymeta/runtime.py:414)
at rule_rule (/pymeta_generated_code/pymeta_grammar__Grammar.py:59)
at _apply (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pymeta/runtime.py:329)
at _G_many_2 (/pymeta_generated_code/pymeta_grammar__Grammar.py:8)
at many (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pymeta/runtime.py:396)
at rule_compile (/pymeta_generated_code/pymeta_grammar__Grammar.py:11)
at _apply (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pymeta/runtime.py:329)
at apply (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pymeta/runtime.py:299)
at _generate_code (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pybars/_compiler.py:754)
at compile (/base/data/home/apps/project/msg:723c.394507766785965429/lib/pybars/_compiler.py:780)
dobesv commented 7 years ago

I am also seeing this issue if I compile template concurrently. I wonder if this library is not thread safe?

    container = self._generate_code(source)
  File "/home/dobes/env/lib/python2.7/site-packages/pybars/_compiler.py", line 801, in _generate_code
    output = self._compiler(tree).apply('compile')[0]
  File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 299, in apply
    val, err = self._apply(r, ruleName, args)
  File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 329, in _apply
    [rule(), self.input])
  File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 11, in rule_compile
    self.considerError(lastError)
  File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 396, in many
    v, _ = fn()
  File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 8, in _G_many_2
    _G_exactly_1, lastError = self.exactly('-')
  File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 329, in _apply
    [rule(), self.input])
  File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 59, in rule_rule
    return (_G_apply_1, self.currentError)
  File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 414, in _or
    ret, err = f()
  File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 32, in _G_or_1
    _G_exactly_1, lastError = self.exactly('0')
  File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 329, in _apply
    [rule(), self.input])
  File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 148, in rule_literal
    def _G_or_6():
  File "<string>", line 1, in <module>
  File "/home/dobes/env/lib/python2.7/site-packages/pybars/_compiler.py", line 589, in add_literal
    self._result.grow(u"    result.append(%s)\n" % repr(value))

The error seems to be inconsistent ... sometimes it works, and sometimes it doesn't.

isaacdd commented 6 years ago

@mselevan @dobesv do you have example templates where this happens?

radove commented 2 years ago

The source code for _compiler.py mentions the compiler is not threadsafe. An alternative way we fixed this without a patch was in our software, we setup lock = threading.Lock(). and then we utilized with lock: for the compiler calls. This blocks other threads from causing issues here. We needed to do this for a project that we have WSGI threads. https://stackoverflow.com/questions/52787026/python-how-to-turn-thread-into-thread-safe