Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter User model full_name field to be non-nullable. #188

Conversation

MichaelRoytman
Copy link
Member

@MichaelRoytman MichaelRoytman commented Oct 2, 2023

JIRA: None.

Description:

This commit makes the User.full_name field non-nullable to ensure that there is only one representation of the empty value - the empty string. Currently, empty values for this field can be either None or the empty string. Because we're transitioning from a nullable to non-nullable state, a default is required to handle existing rows with a null value.

This is best practice; Django discourages setting both null=True and blank=True on CharField model fields. Furthermore, this was required by our event bus work. If an empty value is represented by None, this causes issues with the event bus, because None is not JSON serializable. Instead of converting a None value to the empty string in the event producer, correcting the the model definition is a better approach.

Author concerns: This is the default model definition in the edX cookiecutter. This pattern has been propagated to other applications. I have been unable to find a justification for the choice to set null=True and `blank=True=, but there is the small potential this choice was meaningful.

Dependencies: None.

Installation instructions: None.

Testing instructions: None.

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Delete working branch (if not needed anymore)

@MichaelRoytman MichaelRoytman force-pushed the michaelroytman/user-model-full_name-empty branch from cb28d98 to b37cb09 Compare October 2, 2023 20:38
This commit makes the User.full_name field non-nullable to ensure that there is only one representation of the empty value - the empty string. Currently, empty values for this field can be either None or the empty string. Because we're transitioning from a nullable to non-nullable state, a default is required to handle existing rows with a null value.

This is best practice; Django discourages setting both null=True and blank=True on CharField model fields. Furthermore, this was required by our event bus work. If an empty value is represented by None, this causes issues with the event bus, because None is not JSON serializable. Instead of converting a None value to the empty string in the event producer, correcting the the model definition is a better approach.
@MichaelRoytman MichaelRoytman force-pushed the michaelroytman/user-model-full_name-empty branch from b37cb09 to ea96800 Compare October 2, 2023 20:48
Copy link
Member

@ilee2u ilee2u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@MichaelRoytman MichaelRoytman merged commit 38adf3e into MST-1789-downstream-triggers Oct 2, 2023
5 checks passed
@MichaelRoytman MichaelRoytman deleted the michaelroytman/user-model-full_name-empty branch October 2, 2023 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants