Skip to content

Ability to handle duplicate records #51196

Open

Description

@raisedadead

Add the ability to handle duplicate records at runtime better. That is when we make queries to the DB (like at login, etc.) we should check if multiple documents are available.

If yes, we need to handle the case with proper error messages (and some dev/staff debug info like user ids, etc.)

Some ideas:

  • Implement an equivalent of the Loopback error handling. (Mrugesh)
  • Intercept the session and then check with something like user.findMany and handle it. (Oliver)

Activity

  1. converted this from a draft issue on Aug 9, 2023
  2. added this to the Backend API MVP milestone on Aug 9, 2023
  3. added
    platform: api
    on Aug 9, 2023
  4. self-assigned this
    on Aug 16, 2023
  5. moT01 commented on Apr 30, 2024

    @moT01
    Member

    Is this still mandatory or could we move this to post-mvp?

  6. raisedadead commented on May 6, 2024

    @raisedadead
    MemberAuthor

    I believe the adapter is not as forgiving as our legacy API. I will be needing to check with @ojeytonwilliams

  7. ojeytonwilliams commented on May 7, 2024

    @ojeytonwilliams
    Contributor

    @raisedadead if, by adapter, you mean Prisma, then it should be fine. We can run into problems if the shape of the document is different from the Prisma schema, but that's not the case here.

    Currently what we're doing (in the new api) is getting the first user with that email:

    // TODO: handle the case where there are multiple users with the same email.
    // e.g. use findMany and throw an error if more than one is found.
    const existingUser = await fastify.prisma.user.findFirst({
    where: { email },
    select: { id: true }
    });

  8. raisedadead commented on May 7, 2024

    @raisedadead
    MemberAuthor

    Is findMany more expensive? I mean what is stopping us from implementing the TODO above? It would be great to log these errors right-away in sentry.

  9. ojeytonwilliams commented on May 7, 2024

    @ojeytonwilliams
    Contributor

    I assume they're both fast because email is indexed, but I don't know much about DB performance.

    We could try it, though.

  10. ojeytonwilliams commented on Jul 8, 2024

    @ojeytonwilliams
    Contributor

    @raisedadead is there anything missing from the implementation of #55171 or can we close this?

  11. raisedadead commented on Jul 9, 2024

    @raisedadead
    MemberAuthor

    For now, it would be nice to email the user & support but that can be later.

  12. added
    status: on the roadmap
    on Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

platform: apistatus: on the roadmap

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions