Skip to content

range_error_message raises TypeError when error_message is a translator #664

@anonymous378

Description

@anonymous378
from pydal import validators
from py4web import Translator
# T = Translator("soccer/translations")
# T.select("es")

T = Translator()

# default error message works fine
r = validators.range_error_message(None, what_to_enter = "a number", minimum=1, maximum=8)
print(r)


# string works fine
r = validators.range_error_message("Hello", what_to_enter = "a number", minimum=1, maximum=8)
print(r)

# use of translator fails
# TypeError: unsupported operand type(s) for %: 'lazyT' and 'dict'
r = validators.range_error_message(T("Hello"), what_to_enter = "a number", minimum=1, maximum=8)  
print(r)

I believe the code:
return translate(error_message) % dict(min=minimum, max=maximum)
should be replaced with
return str(translate(error_message)) % dict(min=minimum, max=maximum)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions