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.

Using the optimizer, I get the error "must be str, not Prefetch"

See original GitHub issue

I have some django models:

class UserWorkspace(SafeDeleteModel):
    name = models.CharField(max_length=50)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    instance_groups = models.ManyToManyField(InstanceGroup)


class InstanceGroup(SafeDeleteModel):
    instances = models.ManyToManyField(project)


class project(SafeDeleteModel):
    """
    Projects
    """
    uploaded_file = models.ForeignKey('primavera.UploadedFile', on_delete=models.CASCADE)
    proj_id = models.IntegerField(null=True, help_text="FK to PROJECT table - identifies the project")
    # ...........................


class task(SafeDeleteModel):
    """
    Activities
    """
    uploaded_file = models.ForeignKey('primavera.UploadedFile', on_delete=models.CASCADE)
    task_id = models.IntegerField(null=True, help_text="FK to TASK table - identifies the task")
    proj_id = models.ForeignKey(null=True, help_text="FK to PROJECT table - identifies the project", to="project", on_delete=models.CASCADE, related_name="tasks")
    # ............................

The query looks like this:

def resolver_for_model(model):
    return lambda root, info, **kwargs: gql_optimizer.query(model.objects.all(), info)

class BaseQuery():
    all_user_workspace = graphene.List(type_for_model(UserWorkspace), resolver=resolver_for_model(UserWorkspace))

When I run this query:

{
  allUserWorkspace {
    id
    name
    instanceGroups {
      instances {
        lastRecalcDate
        id
        tasks {
          id
        }
      }
    }
  }
}

I get this error:

graphql.error.located_error.GraphQLLocatedError: must be str, not Prefetch

I looked at that code and tried to replicate the problem by running something like this:

Instance.objects.all().prefetch_related(Prefetch('tasks'))

This works just fine though. I’m not sure what could be causing this error.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tfoxycommented, Jan 13, 2019

Hi! Sorry for the long time. It’s solved in v0.3.6!

0reactions
elmehalawicommented, Jan 15, 2019

Thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

I get the error "must be str, not builtin_function_or_method"
A new file is created by comparing the information from the average speed recording system with the file of registered vehicles and their...
Read more >
FullyShardedDataParallel — PyTorch 1.13 documentation
The optimizer must be initialized after the module has been wrapped, since FSDP will shard parameters in-place and this will break any previously...
Read more >
QuerySet API reference | Django documentation
Returns a new QuerySet containing objects that do not match the given lookup parameters. The lookup parameters ( **kwargs ) should be in...
Read more >
Resource Hints - W3C
A resource hint link is a dns-prefetch , preconnect , prefetch , or prerender relationship that is used to indicate an origin or...
Read more >
qopt-prefetch, Qopt-prefetch - Intel
The goal of prefetching is to reduce cache misses by providing hints to the processor about when data should be loaded into the...
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