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

Support UUID #56

Closed
LostKobrakai opened this issue May 5, 2023 · 10 comments · Fixed by livebook-dev/kino#362
Closed

Support UUID #56

LostKobrakai opened this issue May 5, 2023 · 10 comments · Fixed by livebook-dev/kino#362

Comments

@LostKobrakai
Copy link

When trying to query a table with uuid primary key with postgrex (SELECT * FROM table) I get this error:

Failed to serialize initial widget data, invalid byte 0xD0 in <<208, 115, 222, 115, 28, 225, 73, 163, 144, 184, 76, 109, 162, 124, 182, 190>>
@LostKobrakai
Copy link
Author

As a workaround this seems to work SELECT id::text FROM table, but that also means one can no longer use *.

@jonatanklosko
Copy link
Member

Raw UUID is binary and encoding it as JSON string fails. See livebook-dev/kino#192.

@mbaltrusitis
Copy link

As a workaround this seems to work SELECT id::text FROM table, but that also means one can no longer use *.

And for the mirrored workaround where you want to use the output of table.id::text as an input to a future query:

WHERE table.id::text = {{some_value}}

Because the following will not work:

WHERE table.id = {{some_value}}::uuid

@tiagoefmoraes
Copy link

One more time I stumbled on on this and created this workaround:

# Naively maps UUIDs in rows values to string
# depends on https://hexdocs.pm/elixir_uuid/
update_in(postgrex_result, [Access.key!(:rows), Access.all(), Access.all()], fn
  <<_uuid::128>> = value -> UUID.binary_to_string!(value)
  value -> value
end)

@davydog187
Copy link

I just ran into this as well, and I found the behavior quite confusing. Since its very common for UUIDs to be return in queries, might a simple fix here be to add a suggestion to the error message?

e.g.

Failed to serialize initial widget data, invalid byte 0xBB in <<187, 223, 164, 69, 58, 223, 67, 67, 145, 97, 150, 92, 204, 174, 149, 4>>

Suggestion: if you're returning a UUID in your query, try casting it to text e.g. select uuid::text from my_table

What do you think @jonatanklosko

@josevalim
Copy link
Contributor

I think improving the error message can be a good call. @jonatanklosko, do we know the smart cell that triggered the error in Livebook?

@mbaltrusitis
Copy link

I think improving the error message can be a good call. @jonatanklosko, do we know the smart cell that triggered the error in Livebook?

I can reproduce this using a SQL Query Smart Cell.

@jonatanklosko
Copy link
Member

@josevalim it's not specific to smart cell, the query returns %Postgrex.Result{}, which we render as Kino.DataTable, which from Livebook perspective is just Kino.JS.Live, so Livebook gets the data and then tries to serialize it to send it to the iframe. So if we want to add a special-cased error it needs to be more generic:

image

@josevalim
Copy link
Contributor

@jonatanklosko it is either a better error message OR we implement this issue: michalmuskala/jason#12. But that means the UUID above would be rendered as �s�s^<�I�Lm�|� which is hardly helpful.

@jonatanklosko
Copy link
Member

I've just realised it's not really about UUID, the issue is just that Kino.DataTable doesn't inspect non-utf8 binaries, which we can easily do. See livebook-dev/kino#362.

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

Successfully merging a pull request may close this issue.

6 participants