Skip to content

Use direct status code to avoid deprecation warnings.#52252

Closed
ioquatix wants to merge 3 commits into
rails:mainfrom
ioquatix:avoid-deprecated-name
Closed

Use direct status code to avoid deprecation warnings.#52252
ioquatix wants to merge 3 commits into
rails:mainfrom
ioquatix:avoid-deprecated-name

Conversation

@ioquatix

@ioquatix ioquatix commented Jul 2, 2024

Copy link
Copy Markdown
Contributor

Motivation / Background

The HTTP status code 422 was informally referred to as "unprocessable entity" by the WebDAV specifications. However, it was officially standardised as "unprocessable content" by the HTTP standards. Rack adopted this change in v3.1 and emits deprecation warnings in v3.2 (HEAD).

The current released versions of Rack work acceptably with Rails, however Rack HEAD emits warnings, causing test failures.

See rack/rack#2137 for more context. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422 for more details about the specifications.

Detail

Use "422" status code directly in exception_wrapper.rb to avoid the deprecation warning. This change bypasses symbolic name lookup and thus the deprecation warning, by using the status code directly. We may prefer to change all the symbolic constants to integer values to avoid extra hash lookups. However, it's probably not a performance issue in practice.

Handle both unprocessible_entity and unprocessible_content in ActionDispatch::Response and the test assertions helper. This ensures compatibility with both symbols going forward, until Rails decides to drop support.

Alternatives

I considered the following alternatives:

  • Don’t emit the warning in Rack head, but restore it later (3.2 in about a years time?)
  • Don’t make it an error if the warning is emitted in Rack head, in Rails test CI.

If there is enough interest in doing it differently, I'd be willing to consider those options.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot Bot added the actionpack label Jul 2, 2024
@ioquatix ioquatix force-pushed the avoid-deprecated-name branch from ff3dba3 to 18ff3f3 Compare July 2, 2024 02:14
@ioquatix ioquatix force-pushed the avoid-deprecated-name branch from 18ff3f3 to d586b37 Compare July 2, 2024 02:14
@Earlopain

Copy link
Copy Markdown
Contributor

Is status= a method that application code could call and thus skip the deprecation warning? I tried basic render ..., status: :unprocessable_entity and that is fine

@ioquatix

ioquatix commented Jul 2, 2024

Copy link
Copy Markdown
Contributor Author

Yes, IIUC, that's a reasonable usage.

I think in the future (e.g. think once Rack 3.0 is dropped), we will probably want to remove this code.

@ioquatix

Copy link
Copy Markdown
Contributor Author

It looks like this is no longer needed as emitting a warning no longer causes test failures.

@ioquatix ioquatix closed this Sep 27, 2024
@ioquatix ioquatix deleted the avoid-deprecated-name branch September 27, 2024 01:40
@Earlopain

Copy link
Copy Markdown
Contributor

The warning was just suppressed here #52751, something should still happen.

@ioquatix

Copy link
Copy Markdown
Contributor Author

I agree.

@Earlopain

Copy link
Copy Markdown
Contributor

Will you reopen or do you consider this done for now? I would recreate it if you have no interest in it anymore.

@ioquatix

Copy link
Copy Markdown
Contributor Author

I am happy to re-open it if there is a path towards getting it merged or rejected (both okay).

@Earlopain

Copy link
Copy Markdown
Contributor

I'd say ask in the discord but I see you already did that🙃. Maybe bump in the discord and reopen?

Earlopain added a commit to Earlopain/rails that referenced this pull request Oct 19, 2024
Using `unprocessable_entity` will emit a warning on Rack 3.2.
There have been various PRs in the past for this:
* rails#52252
* rails#52192
* rails#52087
* rails#52097

This to me seems like the least invasive change and is also how headers are currently handled.
Earlopain added a commit to Earlopain/rails that referenced this pull request Mar 3, 2025
Using `unprocessable_entity` will emit a warning on Rack 3.2.
There have been various PRs in the past for this:
* rails#52252
* rails#52192
* rails#52087
* rails#52097

This to me seems like the least invasive change and is also how headers are currently handled.
Earlopain added a commit to Earlopain/rails that referenced this pull request Jul 23, 2025
Using `unprocessable_entity` will emit a warning on Rack 3.2.
There have been various PRs in the past for this:
* rails#52252
* rails#52192
* rails#52087
* rails#52097

This to me seems like the least invasive change and is also how headers are currently handled.
byroot pushed a commit to Earlopain/rails that referenced this pull request Jul 31, 2025
Using `unprocessable_entity` will emit a warning on Rack 3.2.
There have been various PRs in the past for this:
* rails#52252
* rails#52192
* rails#52087
* rails#52097

This to me seems like the least invasive change and is also how headers are currently handled.
viralpraxis pushed a commit to viralpraxis/rails that referenced this pull request Sep 22, 2025
Using `unprocessable_entity` will emit a warning on Rack 3.2.
There have been various PRs in the past for this:
* rails#52252
* rails#52192
* rails#52087
* rails#52097

This to me seems like the least invasive change and is also how headers are currently handled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants