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

Some GraphQL Queries for Relationships fail on 1.2 #1228

Closed
sirtux opened this issue Jan 4, 2022 · 7 comments · Fixed by #1230
Closed

Some GraphQL Queries for Relationships fail on 1.2 #1228

sirtux opened this issue Jan 4, 2022 · 7 comments · Fixed by #1230
Assignees
Labels
type: bug Something isn't working as expected

Comments

@sirtux
Copy link
Contributor

sirtux commented Jan 4, 2022

Environment

  • Python version: 3.8
  • Nautobot version: 1.2.2

Steps to Reproduce

  1. Have a relationship e.g. between cluster and devices (one to many)
  2. Run a graphql query like:
device(id:"bb91df1c-61ec-4a85-8138-cdb97c6c890e")
{
  name
  rel_cluster_to_device{
    id
  }
  }
}

Expected Behavior

Get the ID of the relationship

Observed Behavior

{
  "errors": [
    {
      "message": "Cannot call only() after .values() or .values_list()",
      "locations": [
        {
          "line": 5,
          "column": 3
        }
      ],
      "path": [
        "device",
        "rel_cluster_to_device"
      ]
    }
  ],
  "data": {
    "device": {
      "name": "R10-S3",
      "rel_cluster_to_device": null
    }
  }
}
@sirtux
Copy link
Contributor Author

sirtux commented Jan 4, 2022

Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]: An error occurred while resolving field DeviceType.rel_device_to_vm
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]: Traceback (most recent call last):
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphql/execution/executor.py", line 452, in resolve_or_error
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return executor.execute(resolve_fn, source, info, **args)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphql/execution/executors/sync.py", line 16, in execute
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return fn(*args, **kwargs)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/nautobot/core/graphql/generators.py", line 139, in resolve_relationship
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     queryset_ids = gql_optimizer.query(
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphene_django_optimizer/query.py", line 40, in query
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return QueryOptimizer(info, **options).optimize(queryset)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphene_django_optimizer/query.py", line 60, in optimize
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return store.optimize_queryset(queryset)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphene_django_optimizer/query.py", line 378, in optimize_queryset
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     queryset = queryset.select_related(*self.select_list)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 1047, in select_related
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     raise TypeError("Cannot call select_related() after .values() or .values_list()")
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]: TypeError: Cannot call select_related() after .values() or .values_list()
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]: Traceback (most recent call last):
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphql/execution/executor.py", line 452, in resolve_or_error
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return executor.execute(resolve_fn, source, info, **args)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphql/execution/executors/sync.py", line 16, in execute
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return fn(*args, **kwargs)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/nautobot/core/graphql/generators.py", line 139, in resolve_relationship
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     queryset_ids = gql_optimizer.query(
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphene_django_optimizer/query.py", line 40, in query
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return QueryOptimizer(info, **options).optimize(queryset)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphene_django_optimizer/query.py", line 60, in optimize
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     return store.optimize_queryset(queryset)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/graphene_django_optimizer/query.py", line 378, in optimize_queryset
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     queryset = queryset.select_related(*self.select_list)
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:   File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 1047, in select_related
Jan 04 10:38:42 dh01-a-06-18 nautobot-server[2465943]:     raise TypeError("Cannot call select_related() after .values() or .values_list()")

@glennmatthews
Copy link
Contributor

Thanks for the report! Looks likely to be a regression introduced by #769. Investigating.

@glennmatthews glennmatthews added the type: bug Something isn't working as expected label Jan 4, 2022
@glennmatthews glennmatthews self-assigned this Jan 4, 2022
@glennmatthews
Copy link
Contributor

Interestingly, this query reproduces the error:

query {
  device(id: "a7c1dcc8-80eb-4754-9981-e2f63a9ab11e") {
    id
    name
    rel_bgp_device_router_id {
      id
    }
  }
}

but the following variant query works just fine:

query {
  device(id: "a7c1dcc8-80eb-4754-9981-e2f63a9ab11e") {
    id
    name
    rel_bgp_device_router_id {
      id
      address
    }
  }
}

@glennmatthews
Copy link
Contributor

Also it's worth noting that the inner id field returned by this query is not the ID of the RelationshipAssociation model instance, it's the ID of the object on the other end of the relationship association (e.g. the Cluster object ID in your example above). Just wanted to make that clear because it tripped me up as well. :-)

glennmatthews added a commit that referenced this issue Jan 4, 2022
…ific queries.

Fixes #1228

Includes a unit test case; currently flagged for skipping due to #446
@glennmatthews glennmatthews changed the title GraphQL Queries for Relationships fail on 1.2 Some GraphQL Queries for Relationships fail on 1.2 Jan 4, 2022
@sirtux
Copy link
Contributor Author

sirtux commented Jan 5, 2022

Hi @glennmatthews,
I just tried the fix from #1230, and it looks good - I just wait for confirmation from @Manawyrm to confirm that.

Do you think this fix can make it into a 1.2.4?

Thanks,
Tom

@Manawyrm
Copy link

Manawyrm commented Jan 5, 2022

Hi @glennmatthews,

yep, the fix looks good, the GraphQL data is now back to the old state! 👍

Thanks,
Tobias

@glennmatthews
Copy link
Contributor

Yes, we're aiming to release a 1.2.3 in the near future and this fix should make the cut for that release. Thanks!

glennmatthews added a commit that referenced this issue Jan 7, 2022
…ific queries (#1230)

* Catch exceptions thrown by graphene-django-optimizer for certain specific queries.

Fixes #1228

Includes a unit test case; currently flagged for skipping due to #446

* Fix comment wording
glennmatthews added a commit that referenced this issue Jan 7, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants