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

[bug]: Unable to upload image with same custom ID even after removing image with that custom ID from storage #948

Open
2 tasks done
jaqb8 opened this issue Sep 14, 2024 · 3 comments
Labels
area:packages issue regarding one of the uploadthing packages bug: medium priority Something isn't working

Comments

@jaqb8
Copy link

jaqb8 commented Sep 14, 2024

Provide environment information

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 655.58 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.3 - ~/.nvm/versions/node/v18.20.3/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.3/bin/npm
    pnpm: 8.6.11 - /usr/local/bin/pnpm
    bun: 1.0.7 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 119.1.60.110
    Chrome: 128.0.6613.138
    Edge: 128.0.2739.67
    Safari: 17.6
  npmPackages:
    @uploadthing/react: ^7.0.1 => 7.0.1
    typescript: ^5.5.3 => 5.5.4
    uploadthing: ^7.0.1 => 7.0.1

Describe the bug

I set customId of a file to one of my entities id (cuid) in middleware.

  imageUploader: f({ image: { maxFileSize: "1MB" } })
    .input(
      z.object({
        landlordId: z.string(),
      }),
    )
    .middleware(async ({ req, input, files }) => {
      const fileOverrides = files.map((file) => ({
        ...file,
        customId: input.landlordId,
      }));
      return { landlordId: input.landlordId, [UTFiles]: fileOverrides };
    })

This only works once - even if I remove the image with the customId from storage and then try to upload a new file with the same customId, the following error appears.

image

Link to reproduction

n/a

To reproduce

  1. Create a file with customId in storage.
  2. Remove the file from storage.
  3. Try uploading a new file with the previously used customId.

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jaqb8 jaqb8 added area:packages issue regarding one of the uploadthing packages 🐛 bug: unconfirmed labels Sep 14, 2024
@markflorkowski markflorkowski added bug: medium priority Something isn't working and removed 🐛 bug: unconfirmed labels Sep 14, 2024
@markflorkowski
Copy link
Collaborator

Can confirm this is an issue. We currently have a unique constraint on appId + customId, and deleted file records (just db row, not files) are retained for a period after deletion, which can cause conflict.

Perhaps we can add status into the unique constraint to avoid this cc @juliusmarminge

@t3dotgg
Copy link
Member

t3dotgg commented Oct 9, 2024

@markflorkowski adding status to the unique constraint sounds like a race condition disaster waiting to happen. Ideally we'd either ignore deleted assets or change their ids once deleted to prevent the clash

@KingXP-Pythoner
Copy link

hit this problem today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:packages issue regarding one of the uploadthing packages bug: medium priority Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants