Manually defining vector_tile_queryset hits the database before the vector tile request
StefanBrand opened this issue · 0 comments
StefanBrand commented
I created a custom View
like this:
class PostGISFeatureViewWithManualVectorTileQuerySet(PostgisMVTView, DetailView):
vector_tile_layer_name = "features"
vector_tile_fields = ('name', )
def get(self, request, *args, **kwargs):
self.vector_tile_queryset = Feature.objects.filter(date="2020-07-07")
return BaseVectorTileView.get(self, request=request, z=kwargs.get('z'), x=kwargs.get('x'), y=kwargs.get('y'))
Then I tested the number of queries like this:
class VectorTileTestCase(VectorTileBaseTest):
def test_num_queries_equals_one(self):
self.maxDiff = None
with self.assertNumQueries(1):
self.client.get(
reverse(
'feature-postgis-with-manual-vector-tile-queryset',
args=(0, 0, 0)
)
)
This test fails because if self.vector_tile_queryset
evaluates any QuerySet
. This is not desired.
django-vectortiles/vectortiles/mixins.py
Lines 21 to 22 in fb2ad8c
My colleague (Thank you!) proposed a fix, that I will create a PR for.