Skip to content
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

inconsistent behavior of filter pulling from context based on name #140

Open
sqlalchemy-bot opened this issue Jun 28, 2010 · 8 comments · May be fixed by #416
Open

inconsistent behavior of filter pulling from context based on name #140

sqlalchemy-bot opened this issue Jun 28, 2010 · 8 comments · May be fixed by #416
Labels
bug Something isn't working compiler low priority

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Michael Bayer (@zzzeek)

this is related to #3 but seems different

from mako.template import Template

x = Template("""
X:
    ${"asdf" | h.foo}
""")

y = Template("""
Y:
    ${"asdf" | z.foo}
""")

z = Template("""
Z:
    ${h}
    ${"asdf" | h.foo}
""")

class h(object):
    foo = str

try:
    print x.render(h=h)
except NameError, e:
    print e

print y.render(z=h)
print z.render(h=h)
@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

the issue is because we consider the identifier 'h' to be declared at parse tree time. the undeclared_identifiers method of Expression and DefTag would need to be modified to walk through the parsed filter expression fully, and only pop out single, undotted identifiers that are present in DEFAULT_ESCAPES instead of everything in DEFAULT_ESCAPES - however, that still wouldn't solve this:

${'foo' | h, h.strip}

I suppose the fix to that would be, because h.strip is there, its undeclared. "h" as a builtin would basically be blown away from that.

the other solution is, don't allow "h.strip" in there. if we work with the regexp in codegen create_filter_callable(), we could have that. It's probably preferable.

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.4"

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • removed milestone (was: "0.4")

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • added labels: easy

@sqla-tester
Copy link
Collaborator

cocolato has proposed a fix for this issue in the main branch:

Support passing custom filters with the same name as built-in flags https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5557

@zzzeek
Copy link
Member

zzzeek commented Dec 7, 2024

1.3.7 is yanked. a test + yank is added in https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5579

@zzzeek zzzeek reopened this Dec 7, 2024
@zzzeek
Copy link
Member

zzzeek commented Dec 7, 2024

add new tests that use 'n' as a default filter argument and ensure 'n' takes effect when used in this way

@zzzeek zzzeek closed this as completed Dec 7, 2024
@zzzeek zzzeek reopened this Dec 7, 2024
@cocolato
Copy link
Contributor

cocolato commented Dec 9, 2024

add new tests that use 'n' as a default filter argument and ensure 'n' takes effect when used in this way添加使用“n”作为默认过滤器参数的新测试,并确保“n”以这种方式使用时生效

I will try this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler low priority
Projects
None yet
4 participants