immich icon indicating copy to clipboard operation
immich copied to clipboard

Failed upload of many files from iOS app due to "date/time field value out of range".

Open mattalat1 opened this issue 11 months ago • 29 comments

The bug

Out of my roughly 11,000 photos that I uploaded from my phone to my server, ~900 or so failed to upload. Checking the container logs reveals this: [Nest] 695 - 02/04/2025, 10:35:14 PM ERROR [Api:AssetMediaService~79jmlv9f] Error uploading file PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z" PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z" at ErrorResponse (/app/immich/server/node_modules/postgres/cjs/src/connection.js:788:26) at handle (/app/immich/server/node_modules/postgres/cjs/src/connection.js:474:6) at Socket.data (/app/immich/server/node_modules/postgres/cjs/src/connection.js:315:9) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:561:12) at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) at Readable.push (node:internal/streams/readable:392:5) at TCP.onStreamRead (node:internal/stream_base_commons:191:23) at TCP.callbackTrampoline (node:internal/async_hooks:130:17) [Nest] 695 - 02/04/2025, 10:35:14 PM ERROR [Api:ErrorInterceptor~79jmlv9f] Unknown error: PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z" PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z" at ErrorResponse (/app/immich/server/node_modules/postgres/cjs/src/connection.js:788:26) at handle (/app/immich/server/node_modules/postgres/cjs/src/connection.js:474:6) at Socket.data (/app/immich/server/node_modules/postgres/cjs/src/connection.js:315:9) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:561:12) at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) at Readable.push (node:internal/streams/readable:392:5) at TCP.onStreamRead (node:internal/stream_base_commons:191:23) at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

It seems to be an issue with the date/time metadata. Possibly similar or the same as this previously closed issue: https://github.com/immich-app/immich/issues/670

Similarly to the above linked issue, if I manually adjust the date/time of a failed photo and click "revert", the photo then uploads.

The OS that Immich Server is running on

Unraid 7.0

Version of Immich Server

1.125.7

Version of Immich Mobile App

1.125.3 build.191

Platform with the issue

  • [x] Server
  • [ ] Web
  • [x] Mobile

Your docker-compose.yml content

/usr/local/emhttp/plugins/dynamix.docker.manager/scripts/docker create --name='immich' --net='bridge' --pids-limit 2048 -e TZ="America/Chicago" -e HOST_OS="Unraid" -e HOST_HOSTNAME="Green" -e HOST_CONTAINERNAME="immich" -e 'DB_HOSTNAME'='192.168.0.79' -e 'DB_USERNAME'='postgres' -e 'DB_PASSWORD'='postgres' -e 'DB_DATABASE_NAME'='immich' -e 'REDIS_HOSTNAME'='localhost' -e 'DB_PORT'='5433' -e 'REDIS_PORT'='6379' -e 'REDIS_PASSWORD'='' -e 'MACHINE_LEARNING_HOST'='0.0.0.0' -e 'MACHINE_LEARNING_PORT'='3003' -e 'MACHINE_LEARNING_WORKERS'='1' -e 'MACHINE_LEARNING_WORKER_TIMEOUT'='120' -e 'DOCKER_MODS'='imagegenius/mods:universal-redis' -e 'PUID'='99' -e 'PGID'='100' -e 'UMASK'='022' -l net.unraid.docker.managed=dockerman -l net.unraid.docker.webui='http://[IP]:[PORT:8080]' -l net.unraid.docker.icon='https://raw.githubusercontent.com/imagegenius/templates/main/unraid/img/immich.png' -p '8080:8080/tcp' -v '/mnt/user/photos/':'/photos':'rw' -v '/mnt/cache/appdata/immich':'/config':'rw' --device='/dev/dri' 'ghcr.io/imagegenius/immich:latest'

Your .env content

n/a

Reproduction steps

  1. Attempt to upload photo from iOS app
  2. Upload fails

Example file that fails upload: Image

...

Relevant log output


Additional information

No response

mattalat1 avatar Feb 05 '25 04:02 mattalat1

I also have this issue uploading from iOS with about 1,000 photos (other 15k uploaded fine). Interesting for me that most of them are from a GoPro. Not sure if the date/time format from GoPro images are causing an issue.

TheDadNerd avatar Feb 05 '25 06:02 TheDadNerd

The same thing happened to me. And similarly it happened with around 1000 photos left after about 15k uploading fine. Of note, this happened to a secondary account on my immich, my primary account added around 15k without issue a week or so ago.

danbush avatar Feb 19 '25 19:02 danbush

Same issue here. First upload from IOS to server with about 14000 images. Around 500 get this error, and Immich tries to upload them every time I open the app, it seems.

pnodseth avatar Feb 21 '25 19:02 pnodseth

Same error here for approximately 9715 assets when trying to upload to Immich via the iOS app. The other 28k images/videos uploaded fine though. The "date/time field value out of range" error repeats below for each of the images and happens each time the Immich iOS app is opened.


[Nest] 17  - 02/25/2025, 4:38:47 PM   ERROR [Api:AssetMediaService~s22e3kvm] Error uploading file PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
    at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26)
    at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6)
    at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
    at Socket.emit (node:events:524:28)
    at addChunk (node:internal/streams/readable:561:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
    at Readable.push (node:internal/streams/readable:392:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
[Nest] 17  - 02/25/2025, 4:38:47 PM   ERROR [Api:ErrorInterceptor~s22e3kvm] Unknown error: PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
    at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26)
    at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6)
    at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
    at Socket.emit (node:events:524:28)
    at addChunk (node:internal/streams/readable:561:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
    at Readable.push (node:internal/streams/readable:392:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
Query failed : {
  durationMs: 1.0748189985752106,
  error: PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
      at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26)
      at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6)
      at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
      at Socket.emit (node:events:524:28)
      at addChunk (node:internal/streams/readable:561:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
      at Readable.push (node:internal/streams/readable:392:5)
      at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
      at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
    severity_local: 'ERROR',
    severity: 'ERROR',
    code: '22008',
    where: "unnamed portal parameter $8 = '...'",
    file: 'datetime.c',
    line: '3773',
    routine: 'DateTimeParseError'
  },
  sql: 'insert into "assets" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "isArchived", "duration", "isVisible", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) returning *',
  params: [
    '83120ac5-f7db-42c1-9cc5-e9228ed3911e',
    null,
    <Buffer 61 a4 07 cd 83 d0 46 88 47 36 c5 1a ab f3 1a 08 98 ab de 54>,
    'upload/upload/83120ac5-f7db-42c1-9cc5-e9228ed3911e/dd/e0/dde02153-99f7-4ccd-90d1-9ef47b2a1564.JPG',
    '440343F4-9F2E-488D-A6A8-14675D06DC3F/L0/001',
    '8ec37b6e1ecfb6098b7421263583df16d12dfbc7f5596c2a24159350219e1ab6',
    2013-11-30T16:05:41.000Z,
    0000-12-30T00:00:00.000Z,
    2013-11-30T16:05:41.000Z,
    'IMAGE',
    false,
    false,
    '0:00:00.000000',
    true,
    'P1130367.JPG'
  ]

gardz avatar Feb 25 '25 05:02 gardz

Same as the above, I'm attempting my first upload from iOS. Unsure if this is related but in the backup section of the app, the backup count is higher than the total. The remainder is at 0 assets yet it still tries to upload files. I've been unable to get the Immich app so say it's completed, it's forever in an uploading state.

immich-server            | [Nest] 17  - 02/28/2025, 1:52:24 PM   ERROR [Api:ErrorInterceptor~anpf3jvz] Unknown error: PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
immich-server            | PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
immich-server            |     at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26)
immich-server            |     at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6)
immich-server            |     at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
immich-server            |     at Socket.emit (node:events:524:28)
immich-server            |     at addChunk (node:internal/streams/readable:561:12)
immich-server            |     at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
immich-server            |     at Readable.push (node:internal/streams/readable:392:5)
immich-server            |     at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
immich-server            |     at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
immich-server            | Query failed : {
immich-server            |   durationMs: 0.7964829999982612,
immich-server            |   error: PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"
immich-server            |       at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26)
immich-server            |       at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6)
immich-server            |       at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
immich-server            |       at Socket.emit (node:events:524:28)
immich-server            |       at addChunk (node:internal/streams/readable:561:12)
immich-server            |       at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
immich-server            |       at Readable.push (node:internal/streams/readable:392:5)
immich-server            |       at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
immich-server            |       at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
immich-server            |     severity_local: 'ERROR',
immich-server            |     severity: 'ERROR',
immich-server            |     code: '22008',
immich-server            |     where: "unnamed portal parameter $8 = '...'",
immich-server            |     file: 'datetime.c',
immich-server            |     line: '3773',
immich-server            |     routine: 'DateTimeParseError'
immich-server            |   },
immich-server            |   sql: 'insert into "assets" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "isArchived", "duration", "isVisible", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) returning *',
immich-server            |   params: [
immich-server            |     '639758d7-9468-473b-b0a6-1cc20579bc86',
immich-server            |     null,
immich-server            |     <Buffer c9 50 e4 9e 50 83 56 e5 98 27 b9 1d 3b d8 a5 d3 59 02 89 25>,
immich-server            |     'upload/upload/639758d7-9468-473b-b0a6-1cc20579bc86/fc/93/fc93a1cf-5e8d-4937-a378-f484e36ee7ce.JPG',
immich-server            |     'BD58E19D-E2F5-4532-8F8F-A74FF66E263F/L0/001',
immich-server            |     'b96c2aaa3b5233b3fd59879b85a39b8e66926ed834c8a98a2462d98df754f2f9',
immich-server            |     2010-07-12T17:12:34.000Z,
immich-server            |     0000-12-30T00:00:00.000Z,
immich-server            |     2010-07-12T17:12:34.000Z,
immich-server            |     'IMAGE',
immich-server            |     false,
immich-server            |     false,
immich-server            |     '0:00:00.000000',
immich-server            |     true,
immich-server            |     'IMG_0466.JPG'
immich-server            |   ]
immich-server            | }

Image

ghost avatar Feb 28 '25 14:02 ghost

Same issue happening for me on a fresh install. 22117 total, 17556 uploaded, and 4561 all with the same error as above.

Unknown error: PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"

Server version: v1.129.0

packetloss404 avatar Mar 11 '25 17:03 packetloss404

FWIW I "solved" this by manually finding the affected photos in Apple photos (iOS) and adjusting the date there. After that they uploaded as expected. Yes, it took a while..

pnodseth avatar Mar 11 '25 17:03 pnodseth

FWIW I "solved" this by manually finding the affected photos in Apple photos (iOS) and adjusting the date there. After that they uploaded as expected. Yes, it took a while..

For sure thought about that but at 4,561 photos to manually find and edit I am kind of discouraged.

packetloss404 avatar Mar 11 '25 17:03 packetloss404

Hi,

I'm experiencing the same issue as described in this thread. When uploading certain images, I get the following error:

PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z"

The affected images seem to have an invalid or corrupted fileModifiedAt timestamp, which defaults to this invalid value. I’ve gathered a sample dataset for further investigation:

📂 Attached ZIP Files:

  • error_images.zip → Contains images that trigger the error. --> error_images.zip
  • valid_images.zip → Contains images taken around the same time that upload without issues. --> valid_images.zip

This might help in pinpointing the exact metadata discrepancy that causes the issue. Let me know if you need additional information!

Thanks for your work on Immich! 🚀

devobern avatar Mar 17 '25 18:03 devobern

I'm having the same issue as well, would it be possible to add some sort of error catcher to the uploader and just use created at timestamp for the modified timestamp if its invalid?

DonLocke avatar Mar 22 '25 15:03 DonLocke

I've got 80 images in this state as well; if there's any debugging or troubleshooting I can offer, including running a beta of the iOS app or the server, please don't hesitate to ask me.

offbyone avatar Mar 30 '25 05:03 offbyone

Hello @offbyone, do you able to identify the problematic file and see if you can export it and post it here?

alextran1502 avatar Mar 30 '25 14:03 alextran1502

Hello @offbyone, do you able to identify the problematic file and see if you can export it and post it here?

Here is one that failed upload for me. It seems like the majority of my failures are screenshots. However, I downloaded it from iCloud and it appears to have set the CreatedDate and ModifiedDate to when I downloaded it. The same thing happens if I download it to my NAS directly from the phone.

I am guessing something must be wrong with the Created or Modified Date properties (perhaps they are not set or something). I don't see a check before it gets entered to the DB. I have never made a PR, but would it make sense to add a check in the uploadAsset function in the AssetMediaService? I guess it could default to the current date?

https://drive.proton.me/urls/1WSS9V0ZJ8#P8tsmU7tANgh

dotfortun3-code avatar Apr 09 '25 02:04 dotfortun3-code

Having the same problem:

[Nest] 273 - 04/22/2025, 6:18:37 PM ERROR [Api:AssetMediaService~3ga3hkkl] Error uploading file PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z" PostgresError: date/time field value out of range: "0000-12-30T00:00:00.000Z" at ErrorResponse (/app/immich/server/node_modules/postgres/cjs/src/connection.js:790:26) at handle (/app/immich/server/node_modules/postgres/cjs/src/connection.js:476:6) at Socket.data (/app/immich/server/node_modules/postgres/cjs/src/connection.js:315:9) at Socket.emit (node:events:524:28) at addChunk (node:internal/streams/readable:561:12) at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) at Readable.push (node:internal/streams/readable:392:5) at TCP.onStreamRead (node:internal/stream_base_commons:191:23) at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

I can see the file as "Failed". From the logs in immich I can see what file is affected. I went in iCloud on my Mac and deleted it so it should be gone on iCloud and iPhone but no matter what I do the error remains on the iPhone. So I am not sure if the backup is frozen or if it is finished and only this one file is missing.

I believe there are two issues:

why is this producing an error instead of overwriting the date? why Is this freezing the upload?

jkoopmann avatar Apr 22 '25 16:04 jkoopmann

I was able to find the image on my iPhone (so it was not synced as deleted probably because the battery on my Mac was low and the sync was stopped...). I deleted it. Now:

Image

So it saved 19146 out of 19049 images (how is that possible?).

And iCloud Download is at 1%...

If I look at Photos on Mac I see a total of 19323 objects... Now what is happening? Is everything synced? If not, why is it stuck at 1%? iOS log says:

Syncing complete. Changes: true FROM AlbumService...

jkoopmann avatar Apr 22 '25 16:04 jkoopmann

Another here with 114 failed photos. The error mentions a date in the past but it seems the error message in the logs says date/time out of range so doesn't make much sense to me. I'm unable to find the images myself to fix so hopefully a fix soon

DHernan avatar May 03 '25 05:05 DHernan

Same issue for me - app says there's 6626 assets left to upload, but they all fail. Because they fail, immich tries to upload them every time I open the app.

I've actually successfully synced my entire library (including these images) before, so they will be duplicates... I deleted the app and reinstalled it recently while troubleshooting a different error, and this has happened consistently since then.

I am not keen on manually updating timestamps for >6k images, so I'm hoping a future update will fix this...

hellotomtom avatar May 22 '25 11:05 hellotomtom

100% the same issue here.

StephanRoemer avatar May 26 '25 07:05 StephanRoemer

Same issue for me. About 3K of my 16K files have this issue. They are all images uploaded from my DSLR. Something must have happened to the date. Not sure.

dcuellar avatar May 29 '25 03:05 dcuellar

I have also the same problem, 5519 failed of 24713 opictures

sveininge79 avatar Jun 01 '25 15:06 sveininge79

Just wanted to follow up here. My issue was due to invalid dates for files I had imported into iCloud in the past from an old camera or scanned developed photos.

I ended up going to the photos app in iOS and adjusting the date and time for each. It sounds like a huge effort but most of these were grouped pictures from several events so I was able to select many at a time and adjust them. I still spent a few hours but it needed to be cleaned up anyways.

I don’t think this is something immich should be responsible for. They could accept the file with the invalid date, yes, but wouldn’t you want to fix it?

dcuellar avatar Jun 01 '25 15:06 dcuellar

Well, in my case the dates are absolutely correct. So changing them didn’t help at all. I think it has to do with the fileModifiedAt attribute which was mentioned by @devobern

StephanRoemer avatar Jun 01 '25 15:06 StephanRoemer

Well, in my case the dates are absolutely correct. So changing them didn’t help at all. I think it has to do with the fileModifiedAt attribute which was mentioned by @devobern

A big majority of the files I didn’t actually have to change the date for. I simply clicked adjust date and then accepted the date that was already there.

Is that what you did with no success?

dcuellar avatar Jun 01 '25 15:06 dcuellar

did try to change time and date on couple 1000 images and only 2-3 images did upload after that. ios app.

sveininge79 avatar Jun 02 '25 05:06 sveininge79

I have the same issue, failed uploads for pictures with params: [ 0000-12-30T00:00:00.000Z, // fileModifiedAt <<<<<< ]

error:

PostgresError: date/time field value out of range

over 500 uploads already failed, how can we fix this?

yabolek avatar Jun 04 '25 05:06 yabolek

quick fix in: /usr/src/app/dist/services/asset-media.service.js

add a function:

function sanitizeDate(dateString) {
  const d = new Date(dateString);

  if (isNaN(d.getTime())) {
    return new Date('1970-01-01T00:00:00Z');
  }

  if (d.getFullYear() < 1970) {
    return new Date('1970-01-01T00:00:00Z');
  }

  return d;
}

and call it on fileCreateAt, fileModifiedAt, localDateTime in create function

async create(ownerId, dto, file, sidecarFile) {

        const asset = await this.assetRepository.create({
            ownerId,
            libraryId: null,
            checksum: file.checksum,
            originalPath: file.originalPath,
            deviceAssetId: dto.deviceAssetId,
            deviceId: dto.deviceId,
            fileCreatedAt: sanitizeDate(dto.fileCreatedAt),
            fileModifiedAt: sanitizeDate(dto.fileModifiedAt),
            localDateTime: sanitizeDate(dto.fileCreatedAt),
            type: mime_types_1.mimeTypes.assetType(file.originalPath),
            isFavorite: dto.isFavorite,
            duration: dto.duration || null,
            visibility: dto.visibility ?? enum_1.AssetVisibility.TIMELINE,
            livePhotoVideoId: dto.livePhotoVideoId,
            originalFileName: file.originalName,
            sidecarPath: sidecarFile?.originalPath,
        });
        if (sidecarFile) {
            await this.storageRepository.utimes(sidecarFile.originalPath, new Date(), new Date(dto.fileModifiedAt));
        }
        await this.storageRepository.utimes(file.originalPath, new Date(), new Date(dto.fileModifiedAt));
        await this.assetRepository.upsertExif({ assetId: asset.id, fileSizeInByte: file.size });
        await this.jobRepository.queue({ name: enum_1.JobName.METADATA_EXTRACTION, data: { id: asset.id, source: 'upload' } });
        return asset;
    }

putzflorian avatar Jun 09 '25 18:06 putzflorian

I figured out a relatively quick way of fixing this when importing many photos from iOS, without having to manually edit each photo:

  • Select a range of images from the timeline around the dates with the failed images.
  • Add all of them to a temporary album (so they can be re-selected).
  • Go to the album, select all, edit date/time and move the year to some other year.
  • Wait a little while for the change to propagate to all the selected photos.
  • Select all again, edit date/time and move the year back to the original year.
  • Delete the temporary album, and re-import the photos to Immich.

This marks all the images as edited, while keeping the original dates. I did this by marking a few years worth of photos and they all imported afterwards with no issues.

dagstuan avatar Jun 10 '25 05:06 dagstuan

I have now 6000 pictures with this issue. Do you think such workaround is doable with that many Files @dagstuan ?

yabolek avatar Jun 11 '25 04:06 yabolek

It did seem to work for me with ~1100 photos at least @yabolek. YMMW and I offer no guarantees 😅

dagstuan avatar Jun 11 '25 05:06 dagstuan

Same here. Immich just started showing this error, previously I imported the same gallery without any problems, so this is a recently added bug.

gelato avatar Jun 25 '25 09:06 gelato