The problem in this case was with my use of TileMill.
When a new layer is created the default setting for its extent is to pre-calculate based on the database table used as input. This means that the layer will only ever be the size of the dataset with which it was initially created.
In this case I had iterated over a subset of my data as a test of my code and the extents were calculated based on the results. When I iterated over the whole data set the code iterated over the entire database but only displayed the results within the previously calculated constraints.
The solution is to create a new layer or set the extents setting in the layer to 'dynamic' rather than 'pre-calculate'