-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_get_size_of_locals
fails for non-hashable values
#79
Comments
Hi @drewler, Thank you for reporting this bug. Pull request #80 fixes this issue by not not building a This example mimics the broken behaviour. import sys
from liquid import Environment
from liquid import Context
from liquid.template import BoundTemplate
class MyRenderContext(Context):
def get_size_of_locals(self) -> int:
if not self.env.local_namespace_limit:
return 0
return (
sum(sys.getsizeof(obj, default=1) for obj in set(self.locals.values()))
+ self.local_namespace_size_carry
)
class MyBoundTemplate(BoundTemplate):
context_class = MyRenderContext
class MyEnvironment(Environment):
local_namespace_limit = 110 # XXX: very low, for demonstration purposes
template_class = MyBoundTemplate
env = MyEnvironment()
template = env.from_string(
"{% assign foo = 'hello' %}"
"{% assign bar = 'world' %}"
).render()
# raises a LocalNamespaceLimitError
template = env.from_string(
"{% assign foo = 'hello' %}"
"{% assign bar = 'world' %}"
"{% assign baz = '!' %}"
).render() And this example simply counts the number of items in the namespace. from liquid import Environment
from liquid import Context
from liquid.template import BoundTemplate
class MyRenderContext(Context):
def get_size_of_locals(self) -> int:
if not self.env.local_namespace_limit:
return 0
return len(self.locals) + self.local_namespace_size_carry
class MyBoundTemplate(BoundTemplate):
context_class = MyRenderContext
class MyEnvironment(Environment):
local_namespace_limit = 2 # XXX: very low, for demonstration purposes
template_class = MyBoundTemplate
env = MyEnvironment()
template = env.from_string(
"{% assign foo = 'hello' %}"
"{% assign bar = 'world' %}"
).render()
# raises a LocalNamespaceLimitError
template = env.from_string(
"{% assign foo = 'hello' %}"
"{% assign bar = 'world' %}"
"{% assign baz = '!' %}"
).render() |
Fixed in version 1.4.7. Now released. |
That was fast. Thank you @jg-rp! |
When setting resource limits for a
Context
's by setting alocal_namespace_limit
, it fails when computing_get_size_of_locals
if any of the values is not hashable (eg: alist
) because it tries to de-duplicate them by putting them in aset
.liquid/liquid/context.py
Lines 468 to 473 in e123ce0
Code reproducing the issue:
The text was updated successfully, but these errors were encountered: