﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35927	utils/encoding.py force_string, smart_string, force_bytes, and smart_bytes should verify encoding parameter is not None	Derek M. Knowlton	Derek Knowlton	"= Overview
The `force_str()`, `force_bytes()`, `smart_str()`, `smart_bytes()` functions in `django/utils/encoding.py` currently doesn't verify that the `encoding` parameter is not `None`. When `None` is passed as the encoding parameter and the input is bytes, it results in a TypeError from Python's built-in `str()` function rather than providing a clear validation error.

= Reproduction
{{{#!python
from django.utils.encoding import force_str

# This raises TypeError: str() argument 'encoding' must be str, not None
result = force_str(b'test', encoding=None)
}}}

= Behaviors
== Current Behavior:
    - When encoding=None is passed by input, a TypeError is raised by Python's built-in str() function
    - The error message from this specific error does not indicate that the error originated from `utils/encoding.py`, or that the error comes from an incorrect value passed to the functions inside `utils/encoding.py`
    - No upfront validation is performed on the encoding parameter

== Expected Behavior:
    - Early detection of invalid encoding parameter
    - Custom TypeError with a descriptive message if None is passed
    - Follows explicit parameter validation principles

= Suggested Fix
{{{#!python
if encoding is None:
    raise TypeError(""{{function name}}: encoding parameter cannot be None"")
}}}

= Summary
Though this change is small, it would improve developer experience by increasing the accuracy of error handling. This change is backwards compatible as it does not change the functionality of the code as passing None was never valid."	Cleanup/optimization	closed	Utilities	5.1	Normal	invalid	encoding, none, smart_str, force_str, smart_bytes, force_bytes, utils	Derek M. Knowlton	Unreviewed	1	0	0	0	0	0
