Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

?_sort=rowid with _next= returns error #1470

Closed
eigenfoo opened this issue Sep 13, 2021 · 4 comments
Closed

?_sort=rowid with _next= returns error #1470

eigenfoo opened this issue Sep 13, 2021 · 4 comments
Labels

Comments

@eigenfoo
Copy link

eigenfoo commented Sep 13, 2021

For example:

This is because the search URL includes the &_next=100 UTM parameter, carried over from where the FTS search was run. However, there isn't a second page in the search results, so a list index out of range error is raised. You can confirm that removing this UTM parameter from the URL returns the appropriate search results.

The FTS search request should strip any _next UTM parameter.


datasette, version 0.58.1
sqlite-utils, version 3.17
@simonw simonw added the bug label Oct 2, 2021
@simonw
Copy link
Owner

simonw commented Oct 7, 2021

Here's the exception:

-> params[f"p{len(params)}"] = components[0]
(Pdb) list
603  	
604  	                # Figure out the SQL for next-based-on-primary-key first
605  	                next_by_pk_clauses = []
606  	                if use_rowid:
607  	                    next_by_pk_clauses.append(f"rowid > :p{len(params)}")
608  ->	                    params[f"p{len(params)}"] = components[0]
609  	                else:
610  	                    # Apply the tie-breaker based on primary keys
611  	                    if len(components) == len(pks):
612  	                        param_len = len(params)
613  	                        next_by_pk_clauses.append(

Debugger shows that components is an empty array, so components[0] cannot be resolved:

-> params[f"p{len(params)}"] = components[0]
(Pdb) params
{'search': 'hello'}
(Pdb) components
[]

So the bug is in this code:

# Figure out the SQL for next-based-on-primary-key first
next_by_pk_clauses = []
if use_rowid:
next_by_pk_clauses.append(f"rowid > :p{len(params)}")
params[f"p{len(params)}"] = components[0]
else:
# Apply the tie-breaker based on primary keys
if len(components) == len(pks):
param_len = len(params)
next_by_pk_clauses.append(
compound_keys_after_sql(pks, param_len)
)
for i, pk_value in enumerate(components):
params[f"p{param_len + i}"] = pk_value

@simonw simonw changed the title FTS search on non-first result pages returns Error 500 ?_sort=rowid with _next= returns error Oct 7, 2021
@simonw
Copy link
Owner

simonw commented Oct 7, 2021

On further investigation this isn't related to _search at all - it happens when you explicitly sort by _sort=rowid and apply a _next

@simonw simonw closed this as completed in 875117c Oct 10, 2021
@simonw
Copy link
Owner

simonw commented Oct 10, 2021

I'll open a separate issue for removing _next= when running a search.

@simonw
Copy link
Owner

simonw commented Oct 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants