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
Adds a third option for strict to raise a Validation Error #136
Conversation
Hi @wolfe — Thanks for the pull request. Sorry it's sat so long. First the tests are failing — they need to be fixed. Next, can you pull the Finally — can you explain — perhaps with pseudo code why we want this? What does it look like from the DRF perspective? (That will form the basis of the documenting the change too.) Thanks — Lets get this resolved! |
Hi @wolfe — I'd like to get this in. Are you still happy to work on it? A few points:
|
Intentions... Yes, glad to help. But been just too, too busy. Thank you On Tue, Nov 25, 2014 at 4:52 PM, Carlton Gibson notifications@github.com
|
@wolfe — no problem! I think this would be a good addition so I'll keep nudging. :-) |
@carltongibson I agree with the suggestions. As for the Enum option, I see two choices --- (1) have a less robust fallback (just a plain class) for Python < 3.4 as now OR (2) Add the source code, https://hg.python.org/cpython/file/3.4/Lib/enum.py, for enum into the repo, and use it as a fallback import for getting the Enum class. Preference? In any event, I agree that the values True and False should get auto-converted with deprecation warning. |
As nice as an enum would be, lets just go for a regular class — for all versions — for now.
True/False: as you say. Excellent. Thanks for the effort! |
I should say, unless you're particularly keen of course. :-) Looking at that source file — it's not going to play nicely with Python 2.6... — which I don't think we can drop just yet. |
Agreed. |
Version 0.9.1 Release
Version 0.9.2 Release
@carltongibson, I've taken @wolfe's changes and reapplied it on top of your develop branch. I also made some tweaks to get the tests passing. Would you be able to take a peek and let me know if I missed anything? Thanks! |
@mdentremont — That looks good. I've been totally snowed under with work but am planning on putting a release together over (say) the next week. I'll review properly and we'll get this in. Awesome. Thanks! |
@carltongibson Thanks for the quick reply, sounds great! |
Version 0.10.0
@@ -266,7 +276,8 @@ def __new__(cls, name, bases, attrs): | |||
class BaseFilterSet(object): | |||
filter_overrides = {} | |||
order_by_field = ORDER_BY_FIELD | |||
strict = True | |||
# What to on on validation errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here.
@wolfe @mdentremont Guys this is great. I just have one issue remaining: can we add just a little to the usage docs explaining the new option? (It needn't be long but the docs are my main concern and I don't want them to get less comprehensive). |
- Do not change the default "This is an exlusion filter" help text - Update test_default_field to expect 'Filter' instead of '' to match new behavior
- Also fix a typo
@carltongibson I have addressed the typo and added the usage docs! |
Thank you, Matt, for taking this on! |
Good work both of you! I'll review and merge. Thanks! |
@wolfe, @mdentremont — Thanks for this gentlemen. Very good. |
Adds a third option for strict to raise a Validation Error
Thank you for adding this feature. How soon can we expect it in the next release? Keep up the good work. |
I want to roll in #264 and then I'll look at a new release. (Until then you can use |
Sounds good. I have to wait for it to be published to pypi before I can use it for our deployment. Thanks again. |
@adam-snyder You know you can |
What's the purpose of displaying _("Filter") as the default help text? I've just upgraded to latest django-filter and suddenly all my filter fields started to display extra "Filter" text. I found that this comes from this pull request (aioTV@90d244b). |
I don't recall the specifics... 'twas a while ago. But I agree it should I do prefer consistency --- if help_text is auto-injected for one kind of But I appreciate that the change was backward incompatible, and so may have On Mon, Aug 24, 2015 at 11:24 PM, Jakub Wiśniowski <notifications@github.com
|
Thanks for explanation wolfe. Probably it's more reasonable in case of DRF than in case of a regular filter. I'd say that:
My preference is to go with 1 unless you think that it's good to keep the "filter' for DRF. It's just my 2 cents, as I think that some action is required here to avoid forcing users to override all help_texts in all their filters. |
👍 for any change here. I want avoid write everywhere |
OK. We've got competing use-cases here. I'll add a flag to FilterSet (and propagate that to Filter) to enable/disable auto-populating the help text. This will keep it nice and declarative. I'll have the default be disable auto-populating — I think that's less surprising. Unless someone jumps in with a PR, that'll not be instantly. In the meantime, rather than downgrade, I suggest overriding |
I too was surprised by this change. I ended up doing what Carlton suggested with something like this: # specify empty string for help text to suppress on the filter form
for key in self.filters.iteritems():
self.filters[key[0]].extra.update(
{'help_text': ''}
) |
* master: migrations Follow PEP 0008 Remove help text for filter's form - see see carltongibson/django-filter#136 new fields introduced according to the latest experts algorithm. Note: migrations are not created yet. Conflicts: company/forms.py pola/logic.py
I supplied this third option so that Django Rest Framework could return a 400 w/ an appropriate error message.
If this is to your liking, Alex, I'd be glad to add some unit tests before you merge.
Note the bizarre constants True, False, "RAISE" -- I did this to support backward compatibility. If you recommend a cleaner way to manage the strict options, let me know. Someone here recommended another boolean option, but then there'd be 4 possible values of the two booleans, only three of which make sense. I think this is more robust.