Skip to content

fix: handle aliases with dashes in DjangoGetter attribute resolution#1727

Open
Thiago88pe wants to merge 1 commit into
vitalik:masterfrom
Thiago88pe:fix/django-getter-dash-alias
Open

fix: handle aliases with dashes in DjangoGetter attribute resolution#1727
Thiago88pe wants to merge 1 commit into
vitalik:masterfrom
Thiago88pe:fix/django-getter-dash-alias

Conversation

@Thiago88pe
Copy link
Copy Markdown

Fix TemplateSyntaxError when a Schema field uses an alias containing a dash (e.g. alias="CloudFront-Policy").

DjangoGetter.getattr was falling through to Django's template Variable(key).resolve() even for keys that are invalid template variable names. Django's parser rejects dashes, raising TemplateSyntaxError instead of a catchable error.

The fix adds a guard using re.compile(r"^[\w.]+$") to skip Variable.resolve for keys that contain characters outside the set Django Template Variables accept (word chars and dots). Dotted paths like "boss.name" continue to work normally.

Fixes: aliases with - in name (e.g. AWS CloudFront cookies headers). Fixes #1660

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TemplateSyntaxError: Invalid character ('-') in variable name: 'CloudFront-Policy'

1 participant