Skip to content

fix: add asset upload medium test#25144

Merged
jrasm91 merged 1 commit intomainfrom
fix/asset-upload-medium-test
Jan 8, 2026
Merged

fix: add asset upload medium test#25144
jrasm91 merged 1 commit intomainfrom
fix/asset-upload-medium-test

Conversation

@jrasm91
Copy link
Member

@jrasm91 jrasm91 commented Jan 8, 2026

  • Add medium test for asset upload service method
  • Make metadata optional in open api, to match the runtime checks

Follow up to #25143

@timonrieger
Copy link
Collaborator

perfect, i just had issue with this being marked required in the spec 😄

@jrasm91 jrasm91 enabled auto-merge (squash) January 8, 2026 21:41
@jrasm91
Copy link
Member Author

jrasm91 commented Jan 8, 2026

@timonrieger what use case are you using metadata for?

@jrasm91 jrasm91 merged commit 191401f into main Jan 8, 2026
83 of 85 checks passed
@jrasm91 jrasm91 deleted the fix/asset-upload-medium-test branch January 8, 2026 22:01
if (items.length === 0) {
return [];
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

True but this repo method might be used in other places in the future. The typing for the method itself doesn't preclude sending empty values but the database will throw an error so it's seems like an appropriate place to include it.

You could revert the length change but a check is still needed either way because it can be undefined so let's just leave it as is.

@timonrieger
Copy link
Collaborator

@timonrieger what use case are you using metadata for?

i am building https://github.com/timonrieger/immich-python-client, and currently dealing with the upload endpoint to make it accessible. It's auto generated from the openapi spec, so since metadata is marked as required i faced issues. I manually patched the following error, but server-side is the correct place obv.

passing metadata=[] gave me this error, removing it entirely works

{"message":["metadata must be valid JSON"],"error":"Bad Request","statusCode":400,"correlationId":"8gtc2p8v"}

The server does not handle empty values correctly. to reproduce could you test this on the latest main build (i don't have a machine available rn)

printf '\xFF\xD8\xFF\xD9' > /tmp/minimal.jpg
curl -X POST "http://localhost:2283/api/assets" \
  -H "x-api-key: api-key" \
  -F "assetData=@/tmp/minimal.jpg" \
  -F "deviceAssetId=test-fails" \
  -F "deviceId=test-client" \
  -F "fileCreatedAt=2024-01-15T10:30:00.000Z" \
  -F "fileModifiedAt=2024-01-15T10:30:00.000Z" \
  -F 'metadata=[]'

Note

Your PR should fix this insofar as the client would know that this is an optional field now and can omit the metadata field entirly. for the sake of completeness, commenting here nevertheless

will file a PR nevertheless

@jrasm91
Copy link
Member Author

jrasm91 commented Jan 8, 2026

This is bringing up some old memories. I think that because this endpoint uses form data to accept the upload file, you have to send the other data as form fields as well. And, I don't think it's actually possible to natively send a list of json objects in a single form field. You would need to manually stringify it or something.

@timonrieger
Copy link
Collaborator

This is bringing up some old memories. I think that because this endpoint uses form data to accept the upload file, you have to send the other data as form fields as well. And, I don't think it's actually possible to natively send a list of json objects in a single form field. You would need to manually stringify it or something.

yes, form data is always stringified. Sending patch

@jrasm91
Copy link
Member Author

jrasm91 commented Jan 8, 2026

Oh, I already fixed this in #21594. If you stringify the metadata before sending it, it should just work.

@timonrieger
Copy link
Collaborator

Oh, I already fixed this in #21594. If you stringify the metadata before sending it, it should just work.

just figured, my patch is unnecessary, handling weird cases assuming the client is dumb 🤣 . stopping here now…thanks for the fix

@timonrieger
Copy link
Collaborator

timonrieger commented Jan 8, 2026

btw. i recognized that server-side optional properties are often typed with !. Why do you do that?
e.g. https://github.com/immich-app/immich/blob/main/server/src/dtos/time-bucket.dto.ts#L195:L210

runtime tells me that these field sometimes don't exists (as expected from optional)

# Get time bucket assets with coordinates (to check if latitude/longitude are present)
curl -X GET "http://localhost:2283/api/timeline/bucket?timeBucket=2024-01-01&withCoordinates=true" \
                          -H "x-api-key: key" \
                          -H "Accept: application/json"
# contains coordinates data
{..., "latitude": [], "longitude": []}


curl -X GET "http://localhost:2283/api/timeline/bucket?timeBucket=2024-01-01" \
                          -H "x-api-key: key" \
                          -H "Accept: application/json"
# no coordinates data
{...}

Should these be changed to latitude?: number[] and longitude?: number[] to match the spec and runtime, or is there a reason to keep !?
Low risk as of know since no server code uses this DTO internally. But would make types match runtime behavior.

@jrasm91
Copy link
Member Author

jrasm91 commented Jan 8, 2026

I think those might be dynamic based on that query parameter. Time buckets specifically are a very specialized thing that's only meant to be used with immich-web so I wouldn't rely on them not changing in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants