Skip to content

Error deleting an entity after adding it #2

@jcsilvers

Description

@jcsilvers

Current build does not allow you to create an entity and then with another mutation delete that entity.

Steps to reproduce:

  1. Create Add Mutation
  2. Create Delete Mutation
  3. Add item
mutation ($day: DayInput!)  {
  createDay(day:$day){
    id
    agendaDay
  }
}

mutation ($day: DayInput!)  {
  createDay(day:$day){
    id
    agendaDay
  }
}

  1. Immediately try and delete
mutation ($dayId: Int!)  {
  deleteDay(dayId:$dayId){
    id
    agendaDay
  }
}

{
  
	"dayId" : "7004"
  
}

I get the following error

{
 "data": {
   "deleteDay": null
 },
 "errors": [
   {
     "message": "There was an error deleting 7004: The instance of entity type 'Day' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.",
     "locations": [
       {
         "line": 2,
         "column": 3
       }
     ],
     "path": [
       "deleteDay"
     ]
   }
 ]
}

I believe this line is the reason

var sp = services.BuildServiceProvider();
services.AddSingleton<ISchema>(new MITSSchema(new FuncDependencyResolver(type =>sp.GetService(type))));

I replaced it with below and it works as expected.

services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions