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

Error parsing timestamp #148

Closed
pm64 opened this issue Jan 17, 2024 · 6 comments · Fixed by #151
Closed

Error parsing timestamp #148

pm64 opened this issue Jan 17, 2024 · 6 comments · Fixed by #151
Assignees
Labels
bug Something isn't working

Comments

@pm64
Copy link

pm64 commented Jan 17, 2024

Describe the bug
API request appears to fail due to a timestamp parsing error.

To Reproduce
Steps to reproduce the behavior:

  1. Execute the following test:
            var baseAddress = new Uri("http://paperless_host");
            var token = "your-token-here";

            var assemblyName = typeof(IPaperlessClient).Assembly.GetName();
            var assemblyShortName = assemblyName.Name ?? assemblyName.FullName.Split(',').First();
            ProductInfoHeaderValue userAgent = new(assemblyShortName, assemblyName.Version?.ToString());

            var client = new HttpClient
            {
                BaseAddress = baseAddress
            };

            client.DefaultRequestHeaders.UserAgent.Add(userAgent);

#if NET6_0_OR_GREATER
            client.DefaultRequestHeaders.Add("Accept", $"{MediaTypeNames.Application.Json}; version=2");
#else
			client.DefaultRequestHeaders.Add("Accept", "application/json; version=2");
#endif
            client.DefaultRequestHeaders.Authorization = new("Token", token);

            var dtz = DateTimeZoneProviders.Tzdb;
            var so = new PaperlessJsonSerializerOptions(dtz);
            var cc = new CorrespondentClient(client, so);

            var dc = new DocumentClient(client, so);

            var pc = new PaperlessClient(cc, dc);

            var docs = pc.Documents.GetAll();

            await foreach(var doc in docs)
            {
                Console.WriteLine(doc.OriginalFileName);
            }
  1. Observe exception similar to the following:
System.Text.Json.JsonException: 'Cannot convert value to NodaTime.Instant'

Inner Exception
UnparsableValueException: The value string does not match a quoted string in the pattern. Value being parsed: '2023-12-18T00:00:00^-08:00'. (^ indicates error position.)

Expected behavior
A list of documents in the Paperless-ngx instance should be displayed

Screenshots
N/A

Additional context
N/A

@pm64 pm64 added the bug Something isn't working label Jan 17, 2024
@VMelnalksnis
Copy link
Owner

Which paperless version are you using? This package is tested against 1.9.2, so there might have been some changes

@pm64
Copy link
Author

pm64 commented Jan 17, 2024

Indeed, I'm testing against 2.3.3. Is support for modern versions planned?

@VMelnalksnis
Copy link
Owner

Yes, I had started to work on testing against multiple paperless versions, I guess it's time to finally finish it. I'll see if I can reproduce the issue with that version.

@VMelnalksnis
Copy link
Owner

So looks like the issue is not the version, but PAPERLESS_TIME_ZONE because it also controls the API responses. From my testing looks like using OffsetDateTime instead of Instant for response models will fix the issue.

In order to test this I will have to add ability to add new documents to paperless, which complicates this fix a little bit. In v1.9.2 the create document endpoint simply starts the import task and returns OK, so it's not possible to reliably get the created document id. However, in newer versions it returns the task id, so it's possible the import result using the /api/tasks/?task_id={uuid} endpoint. I have a working solution, but I'm not yet sure how I'll add this to the package.

@pm64
Copy link
Author

pm64 commented Jan 18, 2024

Sounds good @VMelnalksnis. I'm happy to assist with testing, just let me know what you need.

@pm64
Copy link
Author

pm64 commented Jan 18, 2024

I just performed a quick test against the updated package and see this issue is now resolved!

Thank you @VMelnalksnis, excited to further explore this useful project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants