Opened 5 years ago

Closed 5 years ago

#30677 closed Cleanup/optimization (fixed)

Improve Exception Message In Test Client and urlencode() when None is passed as data.

Reported by: Keith Gray Owned by: Swatantra
Component: Testing framework Version: dev
Severity: Normal Keywords: test client post
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Keith Gray)

I am upgrading to 2.2.1 from 2.0.5 and my tests are failing due to a change in the test client: https://docs.djangoproject.com/en/2.2/releases/2.2/#miscellaneous. It now throws an exception if a None value is provided in data given to a POST. I would like to propose an improvement to the message to display the offending Key and Value that generate the exception.

I have a proposed change in my fork on github: https://github.com/idahogray/django/tree/ticket_30677

Change History (11)

comment:1 by Keith Gray, 5 years ago

Description: modified (diff)
Has patch: set

comment:2 by Markus Holtermann, 5 years ago

Triage Stage: UnreviewedAccepted

I like your suggestion. I would suggest a slightly different wording:

            raise TypeError(
                "Cannot encode None for key '%s' as POST data. Did you mean "
                "to pass an empty string or omit the value?" % key
            )

comment:3 by Mariusz Felisiak, 5 years ago

Has patch: unset
Summary: Improve Exception Message In Test Client when a None Value is provided to a POSTImprove Exception Message In Test Client when a None Value is provided to a POST.
Version: 2.2master

I agree with Markus' suggestion. Can you create PR via GitHub?

comment:4 by Keith Gray, 5 years ago

I will change the wording and create a PR. I have one more question, can I use f-strings since this is going into master? I cloned the repo and tried to run the tests in a Python 3.5 environment but it wouldn't let me.

comment:5 by Mariusz Felisiak, 5 years ago

Django 3.0 supports Python 3.6+, nevertheless please don't use f-strings (see #29988).

comment:6 by Mariusz Felisiak, 5 years ago

Easy pickings: set

comment:7 by Swatantra, 5 years ago

Owner: changed from nobody to Swatantra
Status: newassigned

comment:8 by Mariusz Felisiak, 5 years ago

Has patch: set
Patch needs improvement: set

comment:9 by Mariusz Felisiak, 5 years ago

Patch needs improvement: unset
Summary: Improve Exception Message In Test Client when a None Value is provided to a POST.Improve Exception Message In Test Client and urlencode() when None is passed as data.
Triage Stage: AcceptedReady for checkin

comment:10 by Keith Gray, 5 years ago

Sorry for the delayed response, i was traveling this week. Thanks for picking this up.

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 73ac9e3:

Fixed #30677 -- Improved error message for urlencode() and Client when None is passed as data.

Note: See TracTickets for help on using tickets.
Back to Top