Opened 2 years ago

Closed 2 years ago

#26179 closed Cleanup/optimization (fixed)

Remove null assignment check for non-nullable foreign key fields

Reported by: Tim Graham Owned by: Zach Liu
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

As raised in #25349 and discussed on django-developers, the following behavior should be removed:

>>> obj.fk = None
ValueError('Cannot assign None: "Obj.fk" does not allow null values.)

(i.e. no more exception if you assign None to a non-nullable foreign key). It applies to ForwardManyToOneDescriptor and ReverseOneToOneDescriptor. The change should be documented in the "backwards-incompatible changes" section of the release notes.

Change History (8)

comment:1 Changed 2 years ago by Tim Graham

A partial implementation of this is on a pull request for #25349.

After this ticket is completed, we'll rebase that pull request and proceed with that fix.

comment:2 Changed 2 years ago by Tim Graham

Easy pickings: set

comment:3 Changed 2 years ago by Zach Liu

Owner: changed from nobody to Zach Liu
Status: newassigned

comment:4 Changed 2 years ago by Zach Liu

I have made the changes and created the pull request ticket_26179

I removed both value=None check in ForwardManyToOneDescriptor and ReverseOneToOneDescriptor.

Because of that, several tests failed because they have assertRaise for ValueError. So I removed those tests.

It passed all tests after that on sqlite.

This is my first time working on Django. So please let me know if there's anything I can do better:)

Thanks.

Last edited 2 years ago by Zach Liu (previous) (diff)

comment:5 Changed 2 years ago by Tim Graham

Has patch: set
Patch needs improvement: set

PR (please add a link like this in the future)

You should also check "Has patch" on the ticket so it appears in the review queue. Since I left some comments for improvement on the pull request, I'll mark "Patch needs improvement." Please uncheck it after you update the pull request. Thanks!

comment:6 Changed 2 years ago by Zach Liu

Thanks for the help. I have updated the pull request (tests for None allowed) and also the backwards-incompatible changes in 1.10.txt.

will remember to update the ticket going forward.

comment:7 Changed 2 years ago by Tim Graham

Patch needs improvement: unset

comment:8 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 04e13c8:

Fixed #26179 -- Removed null assignment check for non-nullable foreign key fields.

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