Skip to content

Made 'default' and 'default_if_none' filters bypass FastDev template exceptions#57

Merged
boxed merged 13 commits intoboxed:masterfrom
Naggafin:containment
May 15, 2025
Merged

Made 'default' and 'default_if_none' filters bypass FastDev template exceptions#57
boxed merged 13 commits intoboxed:masterfrom
Naggafin:containment

Conversation

@Naggafin
Copy link
Contributor

@Naggafin Naggafin commented May 4, 2025

this change makes it so that non-existent context variables in templates will not raise a FastDev exception if they are being filtered by |default or |default_if_none. instead, it defaults to standard Django template behavior, returning None on the lookup, which gets passed to either of those filters. this is probably what most people would have expected as standard behavior from FastDev in templates–it certainly makes sense and is a succinct way to populate a dubious context variable that may or may not have been declared in the view context.

@boxed
Copy link
Owner

boxed commented May 7, 2025

I like it! Could you add a trivial test for this?

@boxed
Copy link
Owner

boxed commented May 15, 2025

I removed the behavior that |default_if_none does not crash on non-existent variables. The filter name explicitly says to check for None, so not-existing doesn't qualify. You would have to do non_existent|default:None|default_if_none:"foo" in that case I think.

@boxed boxed merged commit 9d5593b into boxed:master May 15, 2025
1 check passed
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.

2 participants