Skip to content

DjangoFilterConnectionField seems to disregard filtered queryset #90

Closed
@jole78

Description

@jole78

Given the following code:

class Report(DjangoObjectType):
	class Meta:
		model = ReportModel
		interfaces = (graphene.Node, )
		filter_fields = {
			'state': ['exact'],
		}

class Query(graphene.AbstractType):
	reports = DjangoFilterConnectionField(Report)

	def resolve_reports(self, args, context, info):
		return ReportModel.objects.filter(created_by=context.user)

When I issue the following query:

{
  reports(state: "draft") {
    edges {
      node {
        id
        state        
      }
    }
  }
  __debug {
    sql {
      raw_sql
      params
    }
  }
}

I get the following:

          "raw_sql": "SELECT COUNT(*) AS \"__count\" FROM \"myapp_report\" WHERE \"myapp_report\".\"created_by_id\" = %s",
          "params": "[3]"

You can see that it disregards the filter altogether.

However, if I remove this from the the query:

	def resolve_reports(self, args, context, info):
		return ReportModel.objects.filter(created_by=context.user)

I get the desired result, but then the query is not filtered by user access any more.

Result:

      "sql": [
        {
          "raw_sql": "SELECT COUNT(*) AS \"__count\" FROM \"myapp_report\" WHERE \"myapp_report\".\"state\" = %s",
          "params": "[\"draft\"]"
        },

Am I doing something wrong here or is it a bug? Please advise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions