Closed joealcorn closed 6 years ago
That sounds very fragile to me, not all types will sort in the correct way when they are concatenated as strings. (e.g. 20 < 3
).
If the tuple approach doesn't work on myself, then the project would need a lot more work to manually reconstruct the cursor. Personally I'd rather document this as a limitation of the project.
Fair enough, you are right it is fragile, I've run into an edge case already (and expecting more). I may have to put some work in to get it creating proper where
queries on mysql, if I do I'll see about contributing those changes upstream. In the mean time I'll close this PR. :)
When ordering by two or more fields as well as supplying a
cursor
argument to theCurorPaginator.page
function, the ORM will generate a query something along the lines of thisOn mysql this breaks at the
AS '_cursor'
part -OperationalError: (1241, 'Operand should contain 1 column(s)')
.It seems mysql doesn't allow you to select a tuple. To get around this, I'm concatenating the values instead.
With this change, the query generated looks more like this (
as_mysql
logic was taken from here)From my limited testing, this does seem to work (I'm using django 1.9.13), but I'm not 100% certain of the performance impact or potential comparison differences of using
concat
rather than comparing tuples.