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

Update document with custom fields failed. #255

Open
stefanvogelch opened this issue Nov 11, 2024 · 4 comments
Open

Update document with custom fields failed. #255

stefanvogelch opened this issue Nov 11, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@stefanvogelch
Copy link

Dear VMelnalksnis

Thanks a lot for this great library. Everything works fine except updating documents with custom fields. I try to update a document with CustomFields according to integration test example:
var docUpdate = new DocumentUpdate
{
CustomFields = new()
{
Pfad = path,
},
};
return await _paperlessClient.Documents.Update(document.Id, docUpdate);

But it throws this exception:
Unhandled exception. System.Text.Json.JsonException: The object or value could not be serialized. Path: $.CustomFields.
at VMelnalksnis.PaperlessDotNet.Serialization.CustomFieldsConverter1.Write(Utf8JsonWriter writer, TFields value, JsonSerializerOptions options) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed) at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo1 jsonTypeInfo)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonTypeInfo1 jsonTypeInfo) at VMelnalksnis.PaperlessDotNet.Serialization.HttpClientExtensions.PatchAsJsonAsync[TValue](HttpClient httpClient, Uri requestUri, TValue value, JsonTypeInfo1 typeInfo)
at VMelnalksnis.PaperlessDotNet.Documents.DocumentClient.UpdateCore[TDocument,TUpdate](Int32 id, TUpdate update)
at VMelnalksnis.PaperlessDotNet.Documents.DocumentClient.Update[TFields](Int32 id, DocumentUpdate1 document) at PaperlessNgxClient.PaperlessNgxClient.UpdateCustomFieldPath(Document document, String path) at PaperlessNgxClient.DocInfoUpdater.UpdateInfo(List1 ngxDocsAll, List`1 tblDocuments, Int32 flagDeletedID)
at Program.

$(String[] args)
at Program.(String[] args)

My CustomFields class looks like this:
namespace PaperlessNgxClient
{
internal sealed class CustomFields
{
public string? Pfad { get; set; }
}
}

Getting documents like this works fine and also reads custom field data perfect:
await _paperlessClient.Documents.GetAll().ToListAsync();

I'm using version 0.3.3 of paperlessdotnet and Paperless-ngx 2.8.6

Any idea what the problem might be

Thanks, Stefan

@stefanvogelch stefanvogelch added the bug Something isn't working label Nov 11, 2024
@VMelnalksnis
Copy link
Owner

Hi, from you example I could not see where you specify the type for the custom type, but I'd guess you created a class that specifies the type. I ran the integration tests against 2.8.6 and everything passed.

Can you check that the SerializerContext has the exact DocumentUpdate type that you pass to the client? Otherwise it will fail the serialize it.

The other option where it could fail is due to this:

if (_paperlessOptions.CustomFields.Count is 0)
{
	await foreach (var unused in GetCustomFields().ConfigureAwait(false))
	{
	}
}

If it already has some custom field definitions cached, but not the custom field used by this method, then it will fail. For that I'd need more info on how you use the client.

@stefanvogelch
Copy link
Author

stefanvogelch commented Nov 12, 2024 via email

@stefanvogelch
Copy link
Author

Do you need more information about this issue? I would gladly provide them.

@VMelnalksnis
Copy link
Owner

I could not reproduce the issue in either version 2.3.3 and 2.8.6. The only thing I don't see the type of the pfad custom field, I assume it is string. Here's the code I used for testing, maybe I missed something https://github.com/VMelnalksnis/PaperlessDotNet/pull/269/files

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

No branches or pull requests

2 participants