Skip to content
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

Merged
merged 7 commits into from Jul 1, 2015

Conversation

wolfe
Copy link
Contributor

@wolfe wolfe commented Feb 14, 2014

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.

@carltongibson
Copy link
Owner

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 help_text change out into a separate Issue/PR so that it can be assessed on it's own. (It might well be a good change but it doesn't belong hidden in here.)

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!

@carltongibson
Copy link
Owner

Hi @wolfe — I'd like to get this in. Are you still happy to work on it?

A few points:

  1. Tests — yes, please. We need to make sure nothing breaks.
  2. I'm really keen to improve the documentation so something explaining the usage would be awesome.
  3. I agree True, False, "RAISE" is bizarre. Using an enum comes to mind but:
    • Python <3.4
    • Deprecating True and False, mapping them to the new values, but not just breaking them without warning.

@wolfe
Copy link
Contributor Author

wolfe commented Nov 25, 2014

Intentions... Yes, glad to help. But been just too, too busy. Thank you
so much for the extra nudge!

On Tue, Nov 25, 2014 at 4:52 PM, Carlton Gibson notifications@github.com
wrote:

Hi @wolfe https://github.com/wolfe — I'd like to get this in. Are you
still happy to work on it?

A few points:

  1. Tests — yes, please. We need to make sure nothing breaks.

  2. I'm really keen to improve the documentation so something
    explaining the usage would be awesome.
    3.

    I agree True, False, "RAISE" is bizarre. Using an enum
    https://docs.python.org/3/library/enum.html comes to mind but:

    • Python <3.4
      • Deprecating True and False, mapping them to the new values, but
        not just breaking them without warning.


Reply to this email directly or view it on GitHub
#136 (comment).

@carltongibson
Copy link
Owner

@wolfe — no problem! I think this would be a good addition so I'll keep nudging. :-)

@wolfe
Copy link
Contributor Author

wolfe commented Nov 26, 2014

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

@carltongibson
Copy link
Owner

As nice as an enum would be, lets just go for a regular class — for all versions — for now.

  • I don't want to add a dependency just for this.
  • Branching code on imports... again — not just for this.
  • Perhaps a wistful comment/docstring about the Golden Age to Come :-)

True/False: as you say.

Excellent. Thanks for the effort!

@carltongibson
Copy link
Owner

... lets just go for a regular class ...

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.

@wolfe
Copy link
Contributor Author

wolfe commented Nov 26, 2014

Agreed.

@mdentremont
Copy link
Contributor

@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!

@carltongibson
Copy link
Owner

@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!

@mdentremont
Copy link
Contributor

@carltongibson Thanks for the quick reply, sounds great!

@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here.

@carltongibson
Copy link
Owner

@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).

wolfe and others added 4 commits June 9, 2015 20:53
- 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
@mdentremont
Copy link
Contributor

@carltongibson I have addressed the typo and added the usage docs!

@wolfe
Copy link
Contributor Author

wolfe commented Jun 23, 2015

Thank you, Matt, for taking this on!

@carltongibson
Copy link
Owner

Good work both of you! I'll review and merge. Thanks!

@carltongibson
Copy link
Owner

@wolfe, @mdentremont — Thanks for this gentlemen. Very good.

carltongibson pushed a commit that referenced this pull request Jul 1, 2015
Adds a third option for strict to raise a Validation Error
@carltongibson carltongibson merged commit 73a391a into carltongibson:develop Jul 1, 2015
@adam-snyder
Copy link

Thank you for adding this feature. How soon can we expect it in the next release? Keep up the good work.

@carltongibson
Copy link
Owner

I want to roll in #264 and then I'll look at a new release. (Until then you can use develop)

@adam-snyder
Copy link

Sounds good. I have to wait for it to be published to pypi before I can use it for our deployment. Thanks again.

@carltongibson
Copy link
Owner

@adam-snyder You know you can pip install ... straight from a GitHub branch right? https://pip.pypa.io/en/latest/reference/pip_install.html#git

@restless
Copy link

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).

@wolfe
Copy link
Contributor Author

wolfe commented Aug 25, 2015

I don't recall the specifics... 'twas a while ago. But I agree it should
have been a separate pull request. Of course, the main point of the pull
request was to pay attention to the argument help_tex, so you can set
help_text='' if you prefer.

I do prefer consistency --- if help_text is auto-injected for one kind of
filter (the exclusion filter) it should be for all. I vaguely recalled that
this resulted in the best experience when combined with Django REST
Framework which can potentially auto-generate lots of fields with
auto-generated help text.

But I appreciate that the change was backward incompatible, and so may have
been ill-advised. Perhaps settings like DJANGO_FILTER_FILTER_HELP_TEXT and
DJANGO_FILTER_EXCLUSION_HELP_TEXT are advised?

On Mon, Aug 24, 2015 at 11:24 PM, Jakub Wiśniowski <notifications@github.com

wrote:

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/django-filter@90d244b
aioTV@90d244b).


Reply to this email directly or view it on GitHub
#136 (comment).

@restless
Copy link

Thanks for explanation wolfe. Probably it's more reasonable in case of DRF than in case of a regular filter. I'd say that:

  1. I think that no value for a regular filter field is ok and doesn't break consistency. I'd compare it to a situation where a developer is encouraged to avoid commenting the obvious code. The exclusion filter is breaking the obviousness about how filter works so it has its "comment".
  2. Extra settings would work for me too

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.

@ad-m
Copy link
Contributor

ad-m commented Aug 26, 2015

👍 for any change here. I want avoid write everywhere help_text="". I was also surprised by the change. I now have everywhere the same comment, the constant repetition.

ad-m added a commit to watchdogpolska/feder that referenced this pull request Aug 26, 2015
@carltongibson
Copy link
Owner

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 __init__ on your FilterSet to loop through filters and set the extras["help_text"] key there.

@rjschave
Copy link

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': ''}
    )

mik-laj pushed a commit to KlubJagiellonski/pola-backend that referenced this pull request Oct 14, 2015
jakublipinski added a commit to KlubJagiellonski/pola-backend that referenced this pull request Oct 15, 2015
* 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
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.

None yet

7 participants