datasette: If a row has a primary key of `null` various things break

Stumbled across this while experimenting with datasette-write-ui. The error I got was a 500 on the /db page:

'NoneType' object has no attribute 'encode'

Tracked it down to this code, which assembles the URL for a row page:

https://github.com/simonw/datasette/blob/943df09dcca93c3b9861b8c96277a01320db8662/datasette/utils/__init__.py#L120-L134

That’s because tilde_encode can’t handle None: https://github.com/simonw/datasette/blob/943df09dcca93c3b9861b8c96277a01320db8662/datasette/utils/__init__.py#L1175-L1178

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 23 (22 by maintainers)

Most upvoted comments

Suggestion from @asg017 is that we say that if your row has a null primary key you don’t get a link to a row page for that row.

Which has some precedent, because our SQL view display doesn’t link to row pages at all (since they don’t make sense for views): https://latest.datasette.io/fixtures/simple_view