Skip to content

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

Open

Description

@sqlalchemy-bot

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)

Activity

  1. sqlalchemy-bot commented on Jun 28, 2010

    @sqlalchemy-bot
    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.

  2. sqlalchemy-bot commented on Jun 28, 2010

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • set milestone to "0.4"
  3. sqlalchemy-bot commented on Nov 13, 2010

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • removed milestone (was: "0.4")
  4. sqlalchemy-bot commented on Feb 21, 2011

    @sqlalchemy-bot
    Author

    Changes by Michael Bayer (@zzzeek):

    • added labels: easy
  5. sqla-tester commented on Dec 3, 2024

    @sqla-tester
    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

  6. added a commit that references this issue on Dec 3, 2024
    f37777c
  7. zzzeek commented on Dec 7, 2024

    @zzzeek
    Member
  8. reopened this on Dec 7, 2024
  9. zzzeek commented on Dec 7, 2024

    @zzzeek
    Member

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

  10. reopened this on Dec 7, 2024
  11. cocolato commented on Dec 9, 2024

    @cocolato
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions