Can't convert '__proxy__' object to str implicitly
See original GitHub issueWhen using the Bootstrap3 inline form field template using lazily translated field labels in the current dev branch, an error is raised on:
{% crispy_field field 'placeholder' field.label %}
The error comes down to:
File "..../django-crispy-forms/crispy_forms/templatetags/crispy_forms_field.py" in render
134. widget.attrs[attribute_name] += " " + template.Variable(attribute).resolve(context)
Exception Type: TypeError at ...
Exception Value: Can't convert '__proxy__' object to str implicitly
This simple str
call resolves the issue:
widget.attrs[attribute_name] += " " + str(template.Variable(attribute).resolve(context))
Using Django 1.7c2 on Python 3.4
Issue Analytics
- State:
- Created 9 years ago
- Comments:5
Top Results From Across the Web
python gettext error: Can't convert '__proxy__' object to str ...
This can be fixed by wrapping the second call to ugettext_lazy() in str() (i.e. the code becomes str( _('link!') ) . Doing this...
Read more >TypeError: Can't convert 'int' object to str implicitly
This error message Can't convert 'int' object to str implicitly is clear, when concatenating strings with integers - you can't directly stick together...
Read more >Proxy objects, symbols, and string conversions - Matt Zeunert
Doing an explicit conversion with p. toString() + " world!" works fine! So what happens when Chrome tries to convert an object to...
Read more >proxies: stratifying toString, valueOf - ES Discuss
Allowing proxies to trap implicit calls to base-level methods but not explicit calls seems weird. If a Dict should not pollute its pseudo-property...
Read more >Python error TypeError Can t convert int object to str implicitly
This error message Can't convert 'int' object to str implicitly is clear, when concatenating strings with integers - you can't directly ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not very familiar with the internals of Django’s lazy objects, but it seems to me like this could be fixed by defining
__radd__
for the values returned byugettext_lazy
.Minimal case of the error:
…So if
lazy_text.__radd__
was defined, I think this bug would be solved.I did a quick test to make sure defining
__radd__
lets us add to strings:@bayersglassey Nice example. This might be worth suggesting as a fix on Django.