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

Validate and normalize emails #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

amrmelsayed
Copy link

This PR accompanies the frontend PR that was recently merged.

The frontend version disables capitalization of emails during data input and this PR enforces lowercase normalization across the database layer.

One thing that will need to be done before pushing this update to production is to lowercase all user emails and eliminate possible email duplicates (due to different casing).

If there are no duplicates in the database, an update query as simple as this should do the trick:
update public.users set email = trim(lower(email))

However, if there are duplicates, this query will fail with duplicate key value violation as the email field has a unique constraint.

A group by query can be used to identify duplicate emails:
select trim(lower(email)) as normalized_email from public.users group by 1 having count(*) > 1

Duplicate accounts will then need to be either merged or deleted, not sure what you have in mind.

I have also switched the data type for emails from str to EmailStr (Pydantic) to add email validation at the API level.

Finally, there is a seperate commit that fixes some typos.

Copy link
Collaborator

@waleedkadous waleedkadous left a comment

Choose a reason for hiding this comment

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

Patching up the db by hand at the moment.

@waleedkadous
Copy link
Collaborator

waleedkadous commented Jan 31, 2025 via email

@amrmelsayed
Copy link
Author

I see, apologies the email-validator package is missing.

When I forked repo, I changed the fastapi plain package to the standard package (i.e. fastapi to fastapi[standard]) which includes the fastapi-cli (useful in dev mode), I wasn't sure why you weren't using the standard dependecies by default, so I didn't push the fastapi depedency update but I forgot that the email-validator is part of the standard dependencies.

I have reset my virtual environment and added the email-validator package on its own.

However I hit another issue related litellm that has just been reported related to a regression affecting python 3.13.
BerriAI/litellm#8081

The current workaround is to avoid using the latest litellm release which I have excluded, check the latest commit for details.

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