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

LF-4037: add default to last name #3092

Conversation

antsgar
Copy link
Collaborator

@antsgar antsgar commented Jan 25, 2024

Description

Add default of '' to last_name colum in users table.
We're currently not setting a default at the db level and have a fallback of '' on the client when we send out the user information from an invitation. To avoid having to set this fallback in each place where we add a user, I defaulted the column and made the field not required at the model level.

Jira link:
https://lite-farm.atlassian.net/browse/LF-4037

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Tested bug by creating a Google account without a last name and verifying that I could use it to log into Litefarm.

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

@antsgar antsgar requested review from a team as code owners January 25, 2024 14:38
@antsgar antsgar requested review from SayakaOno and kathyavini and removed request for a team January 25, 2024 14:38

export const up = async function (knex) {
await knex.schema.alterTable('users', (table) => {
table.string('last_name').notNullable().defaultTo('').alter();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What existed before was really weird... notNullable().defaultTo(null) 😂 . Almost makes me think it was a typo.

My question is why default to empty string instead of just allowing null with .nullable()? It might make it easier to deal with on the frontend but it seems weird to me https://stackoverflow.com/a/44890240

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well the not nullable with a null default is not that weird, essentially null is the default if there's no default if that makes sense. Essentially if you set a column to not nullable and you don't set a default, you're expecting that whoever's inserting a new record will always specify that field, which is totally fine if the field is required and that's what you want to enforce.

To the second point, I'd totally prefer to make this nullable, but that seems higher risk especially in the context of a hotfix since there might be places where the client is expecting a string and is not prepared with nullish coalescing to handle the null scenario, so this seems like the safest choice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok I did not realize it was hotfix 👍

Copy link
Collaborator

@kathyavini kathyavini left a comment

Choose a reason for hiding this comment

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

Yikes so the frontend was doing it 😂

I agree with the comprehensive approach of putting it on the db schema 👍

@@ -158,6 +158,7 @@ const loginController = {
isInvited: user?.status_id === 2,
});
} catch (err) {
console.error(err);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohhh so that's why the new error message didn't come back 🙂

Copy link
Collaborator

@Duncan-Brain Duncan-Brain left a comment

Choose a reason for hiding this comment

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

I am just now realizing that we are inconsistent with full name and first last name between our signup and our profile page 😂 ... so bad.

@Duncan-Brain Duncan-Brain merged commit 37d34df into integration Jan 25, 2024
4 checks passed
@Duncan-Brain Duncan-Brain deleted the LF-4037-SSO-account-cannot-be-created-without-last-name branch January 25, 2024 21:09
antsgar pushed a commit that referenced this pull request Jan 26, 2024
…be-created-without-last-name

LF-4037: add default to last name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants