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 when querying nested content items with list part #14886

Closed
ggkoning opened this issue Dec 12, 2023 · 5 comments
Closed

Error when querying nested content items with list part #14886

ggkoning opened this issue Dec 12, 2023 · 5 comments
Labels
Milestone

Comments

@ggkoning
Copy link
Contributor

ggkoning commented Dec 12, 2023

Describe the bug

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'Use Blog Recipe'
  2. Alter list part on blog content type definition to include Blog content type. ( To enable nesting of blog content type)
  3. create 'a blog'
  4. Create in that blog TWO or more blog items
  5. Use the GraphiQL query to execute the query I provided.

Context

I am using orchard core 1.7.2 headless
I am using Postgres:latest

It does not seem to happen when using SQLite.

It also happens when you nest two different content types both having list property.

Sometimes the query does work after like 10 tries.

Query

query MyQuery {
  blog {
    list {
      contentItems {
        ... on Blog {
          displayText
          contentType
          list {
            contentItems {
              displayText
            }
          }
        }
      }
    }
    contentType
    displayText
  }
}

Expected behavior

You should be able to query nested content items with both having list propery

Error

{
  "errors": [
    {
      "message": "Error trying to resolve field 'contentItems'.",
      "locations": [
        {
          "line": 12,
          "column": 13
        }
      ],
      "path": [
        "blog",
        0,
        "list",
        "contentItems",
        1,
        "list",
        "contentItems"
      ],
      "extensions": {
        "code": "NPGSQL_OPERATION_IN_PROGRESS",
        "codes": [
          "NPGSQL_OPERATION_IN_PROGRESS"
        ]
      }
    }
  ],
  }
@ggkoning ggkoning changed the title Error when querying nested content items with list part Postgresql error when querying nested content items with list part Dec 14, 2023
@sebastienros
Copy link
Member

NPGSQL_OPERATION_IN_PROGRESS looks like a concurrency issue.

Honestly I was telling myself there is no way it would work sometimes, but now I think it would make sense.
It might be because the GraphQL library used has some kind of lazy resolution, and these might be called concurrently. We did change some default settings to prevent that, it might not be sufficient.

@sebastienros sebastienros added this to the 1.x milestone Dec 14, 2023
@ggkoning
Copy link
Contributor Author

Is there anything I can do to help resolve this issue?

@ggkoning
Copy link
Contributor Author

I can confirm that this issue also happens with MySQL

{
  "errors": [
    {
      "message": "GraphQL.Execution.UnhandledError: Error trying to resolve field 'contentItems'.\n ---> System.InvalidOperationException: This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse\n   at MySqlConnector.Core.ServerSession.StartQuerying(ICancellableCommand command) in /_/src/MySqlConnector/Core/ServerSession.cs:line 289\n   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken)\n   at MySqlConnector.MySqlCommand.ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 357\n   at MySqlConnector.MySqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 350\n   at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 434\n   at YesSql.Store.ProduceAsync[T,TState](WorkerQueryKey key, Func`2 work, TState state)\n   at YesSql.Services.DefaultQuery.Query`1.ListImpl()\n   at YesSql.Services.DefaultQuery.Query`1.ListImpl()\n   at OrchardCore.Lists.GraphQL.ListQueryObjectType.LoadPublishedContentItemsForListAsync(IEnumerable`1 contentItemIds, ISession session)\n   at GraphQL.DataLoader.CollectionBatchDataLoader`2.FetchAsync(IEnumerable`1 list, CancellationToken cancellationToken) in /_/src/GraphQL.DataLoader/CollectionBatchDataLoader.cs:line 59\n   at GraphQL.DataLoader.DataLoaderPair`2.GetResultAsync(CancellationToken cancellationToken) in /_/src/GraphQL.DataLoader/DataLoaderPair.cs:line 68\n   at OrchardCore.Lists.GraphQL.ListQueryObjectType.<>c.<<-ctor>b__0_0>d.MoveNext()\n--- End of stack trace from previous location ---\n   at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 396\n   --- End of inner exception stack trace ---",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "blog",
        1,
        "list",
        "contentItems"
      ],
      "extensions": {
        "code": "INVALID_OPERATION",
        "codes": [
          "INVALID_OPERATION"
        ]
      }
    }
  ],
}

@sebastienros
Copy link
Member

@ggkoning best thing you could do would be to find and fix the problem. I would go by identifying the stack trace that triggers the issue, and with some debugging and logging see what ISession instances are used to do the queries, probably a recursive call is doing two queries using the same instance, and I would assume it could be an async task that is not awaited correctly.

@ggkoning ggkoning changed the title Postgresql error when querying nested content items with list part Database error when querying nested content items with list part Dec 18, 2023
@ggkoning ggkoning changed the title Database error when querying nested content items with list part Error when querying nested content items with list part Dec 18, 2023
@ggkoning
Copy link
Contributor Author

@sebastienros I have made an pr with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants