question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error PATCH'ing with json relationship

See original GitHub issue

I’ll do my best to be brief and descriptive.

I should mention the application has two DbContexts and so far everything has been working well.

I have two seperate IDbContextResolvers, one for each of my database contexts. I DI the resolvers, and have seperate base repositories for each database connection and repositories for each model that extend from the two repositories. (As per #269 ).

I have a model EntityA which has a has-one relationship with EntityB

public class EntityA : Identifiable<int>
  [InverseProperty("EntityAs")]
  public virtual EntityB EntityB { get; set; }

EntityB has-many EntityA’s

public class EntityB : Identifiable<int>
    [InverseProperty("EntityB")]
    [HasMany("EntityAs")]
    public ICollection<EntityA> EntityAs { get; set; }

Calling a PATCH to EntityB endpoint works as expected when I DO NOT include the json relationships: ... which include EntityA’s

Calling a PATCH to EntityB endpoint errors when PATCH’ing with relationships included…

 fail: JsonApiDotNetCore.Formatters.JsonApiReader[0]
       An error occurred while de-serializing the payload  JsonApiDotNetCore.Internal.JsonApiException: Failed to deserialize request body ---> System.InvalidOperationException: Unable to resolve service for type 'JsonApiDotNetCore.Data.
IDbContextResolver' while attempting to activate 'JsonApiDotNetCore.Internal.Generics.GenericProcessor`1[EntityA]'.

Endpoints for both EntityA and EntityB work fine, with no issues or other errors. Both EntityA and EntityB belong to the same repository and should fall under the same context resolver. I don’t believe I’m missing anything obvious as everything else has been working perfectly, and I’m not sure if it’s an issue because of the multiple IDbContextResolvers or not.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
joshhuberscommented, Jun 11, 2018

@jaredcnance Looks to be working on my end!

1reaction
jaredcnancecommented, May 10, 2018

@joshhubers this should be fixed by #254.

There is some mixing of concerns in the de-serialization process that required this call:

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/c2e6779abc0f08fb3666b36ea63944cde8092de6/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs#L241

The original approach to updating relationships, was to actually fetch the relationship so EF would track it and it could be updated 😞 . However, #254 is removing that requirement. The reason you are getting the above error is because when we try to resolve the GenericProcessor<EntityA>, it is failing to resolve IDbContextResolver:

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/c2e6779abc0f08fb3666b36ea63944cde8092de6/src/JsonApiDotNetCore/Internal/Generics/GenericProcessor.cs#L25

So, while the error you’re currently experiencing will be fixed soon, I think there may still be some other lurking issues, especially when trying to use the new implementation of json:api v1.1 operations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the JSON patch data from relationships not get ...
I have an Ruby on Rails api where the data is handled in JSON. When I want to update an entity all the...
Read more >
How to Fix the Invalid JSON Error in WordPress
In this article, learn how to fix the invalid JSON error - 'Updating failed. The response is not a valid JSON response.' with...
Read more >
How to Fix the Invalid JSON Response Error in WordPress
The WordPress invalid JSON response error happens in the new Block Editor (AKA Gutenberg) when something goes wrong on your site.
Read more >
How to Fix the Invalid JSON Error in WordPress ...
How to Fix the Invalid JSON Error in WordPress (Beginner's Guide) · 1. Check WordPress URLs in Settings · 2. Fix WordPress Permalink...
Read more >
PUT vs PATCH vs JSON-PATCH
To start off, PUT and PATCH are two different HTTP methods, which are both commonly used in REST APIs. For people who think...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found