Opened 9 years ago

Closed 9 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: dev
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 by Tim Graham, 9 years ago

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 by Tim Graham, 9 years ago

Easy pickings: set

comment:3 by Zach Liu, 9 years ago

Owner: changed from nobody to Zach Liu
Status: newassigned

comment:4 by Zach Liu, 9 years ago

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.

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

Thanks.

Version 0, edited 9 years ago by Zach Liu (next)

comment:5 by Tim Graham, 9 years ago

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 by Zach Liu, 9 years ago

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 by Tim Graham, 9 years ago

Patch needs improvement: unset

comment:8 by Tim Graham <timograham@…>, 9 years ago

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