-
Notifications
You must be signed in to change notification settings - Fork 349
Ignore --fail-on-template-vars with default filter? #471
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
Comments
I don't know. It's currently failing whenever Django raises a |
The point of the default filter is to handle this, isn't it? |
Hm... default is for false values, not for none existing ones. So if your value |
Fair point. |
I think this is a good feature request. It's a valid and common pattern to have in base.html I don't think it's accurate that "default is for false values, not for none existing ones". Django documentation specifies that non-existent values render to empty string (and that the built-in templates rely on this), and that |
@jcushman you make a good point, but one could argue the other way, that a context should be consistent, no matter what scenario. Values can be None, but the key should exist. |
@jcushman Thanks for PR #922, I'm replying in the issue to keep the discussion in one place.
I think as long as BTW, from the Django docs:
I haven't tried it, but this implies that you can replace |
I looked into the documentation for both the I understand the frustration, but this warning is meant to keep inform if you have diverted from the intended path. Therefore, I must conclude that the feature is correct right now, and I am not in favor of #922. I hope you can understand. |
Sorry to go on about this so much, but this really feels like a misunderstanding.
Missing variables are explicitly defined to resolve to the empty string, unless a test harness like pytest-django is temporarily setting it to something else only for testing. (docs link) If And there's a Django test that connects these dots, making sure that This behavior is documented and depended on elsewhere in Django. For example the docs for
Should we send a pull request asking Django to change that documentation because pytest-django flags it as bad style and recommends the longer version
Django works this way because it's nicer in common cases, not just rare cases. A very common case is template inheritance:
I think you're saying that this example code is bad style and diverges from Django's documentation, and the correct way would be the longer alternative That's where the problem with third party packages like django-pipeline comes in. For myself, I can adhere to pytest-django's preferred linting style in exchange for getting warnings for |
I think this test actually demonstrates the opposite -- that when I understand where you're coming from, but this seems like something that should be resolved on the Django side. Either they say:
or
For myself, I think it would have been better if Django made |
Here's what the docs say:
|
(And, it's really cool that pytest-django is able to get something useful out of |
Hi there, So, there was no misunderstanding on my side, I simply have a different opinion. Don't get me wrong, I understand your reasoning, but I am simply using it differently right now, thus have limited intention of changing that. I believe it's clear at this point, that you are proposing a breaking change unless it would be an optional change, that people would need to activate. And this is really where I have a problem. I don't want to bloat this package too much. It's hard to maintain packages and adding more features makes it harder. Especially if you base your feature on undocumented APIs that may break in any release. I wrote the original implementation, and I am happy to maintain its functionality going forward. However, I am very hesitant to blow it up too much. Allow me one last side note. You correctly mentioned falsely values. However, a Best, |
Fair enough! You asked before to see a suggestion for how to implement it, so the PR was meant to show how complex that would be. If it's too complex it's too complex. 🤷♂️
For sure, but exactly the same errors will be swallowed by In a perfect world it would be great to have two separate lints like
But I definitely get that "fail when Django calls |
django/django#8200 was not accepted, but I think it's good to not fail with
{{ foo | default:"bar" }}
withfoo
being undefined.@codingjoe
What do you think?
The text was updated successfully, but these errors were encountered: