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

Allow None as redirect_field_name value for user_passes_test and login_required #1600

Merged
merged 1 commit into from Jun 28, 2023
Merged

Allow None as redirect_field_name value for user_passes_test and login_required #1600

merged 1 commit into from Jun 28, 2023

Conversation

JoeHitchen
Copy link
Contributor

According to the Django documentation, the redirect_field_name argument to user_passes_test accepts None as a value as well as a string, but Django Stubs currently only recognises strings as acceptable values. Specifically, passing a None indicates that the redirect field should be omitted.

The documentation does not explicitly state whether redirect_field_name of login_required allows or does not allow None values, but my own usage indicates that it does and it behaves in the same way.

I haven't attempted to make this change globally for all instances of redirect_field_name since I'm not familiar with all their usages, but note that some cases already allow Nones while others that still won't.

  • Precommit checks run successfully
  • pytest runs with 31 failures (344 passes), however this is the same as I get on master
  • I don't have a Linux system to run stubtest.sh

There is not an open issue related to this as far as I am aware - I noticed the problem and since it was a simple solution I went straight to fixing.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Yes, you are right.

  1. Source: https://github.com/django/django/blob/21e686471598d6c755d93a570de20dc00d8d27f6/django/contrib/auth/views.py#L186
  2. We already have redirect_field_name annotated as Optional:
    def redirect_to_login(
    next: str, login_url: str | None = ..., redirect_field_name: str | None = ...
    ) -> HttpResponseRedirect: ...

@sobolevn sobolevn merged commit fd905b5 into typeddjango:master Jun 28, 2023
14 checks passed
@JoeHitchen
Copy link
Contributor Author

Cheers!

descope bot added a commit to descope/django-descope that referenced this pull request Jul 20, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [django-stubs](https://togithub.com/typeddjango/django-stubs)
([changelog](https://togithub.com/typeddjango/django-stubs/releases)) |
dev | patch | `4.2.2` -> `4.2.3` |

---

### Release Notes

<details>
<summary>typeddjango/django-stubs (django-stubs)</summary>

###
[`v4.2.3`](https://togithub.com/typeddjango/django-stubs/releases/tag/4.2.3)

[Compare
Source](https://togithub.com/typeddjango/django-stubs/compare/4.2.2...4.2.3)

This version fixes two regressions in previons `django-stubs` release
and also a few other fixes and improvements. Special thanks to
[@&#8203;GabDug](https://togithub.com/GabDug) for contributing
regression fixes on a short order.

This time there is no corresponding release of `django-stubs-ext`.

##### Stubs fixes

- Fixed type error when subclassing `AppConfig` and assigning string to
`default_auto_field` by [@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1596
- Fixed type error when subclassing `MiddlewareMixin.__call__()` and
using `return self.get_response()` by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1595
- Allow `None` as `redirect_field_name` value for `@user_passes_test`
and `@login_required` decorators by
[@&#8203;JoeHitchen](https://togithub.com/JoeHitchen) in
[typeddjango/django-stubs#1600

##### Plugin fixes

- Fixed long-standing issue with `Date(Time)Field` when using mypy
setting `disallow_any_explicit` by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1599

##### Stubs changes

- Added `BigIntegerField.MAX_BIGINT` attribute by
[@&#8203;asottile](https://togithub.com/asottile) in
[typeddjango/django-stubs#1598
- Improved Jinja2 types and updated `pytest-mypy-plugins` by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1601

##### CI/Testing

- Run tests in multiple shards and all Python versions by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1603

##### Housekeeping

- Converted `_typeshed.Self` usages to `typing_extensions.Self` (PEP
673) by [@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1591
- Version 4.2.3 release (django-stubs only) by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1604

#### New Contributors

- [@&#8203;JoeHitchen](https://togithub.com/JoeHitchen) made their first
contribution in
[typeddjango/django-stubs#1600

**Full Changelog**:
typeddjango/django-stubs@4.2.2...4.2.3

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xLjExIiwidXBkYXRlZEluVmVyIjoiMzYuMS4xMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: descope[bot] <descope[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants