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

16 character string converted to UUID #9

Open
sh41 opened this issue Jun 24, 2022 · 7 comments
Open

16 character string converted to UUID #9

sh41 opened this issue Jun 24, 2022 · 7 comments

Comments

@sh41
Copy link
Contributor

sh41 commented Jun 24, 2022

Hi, Thanks again for this project!

There seems to be something not quite right around converting parameters to UUIDs. All 16 character strings seem to get converted into UUIDs.

image

Running the SQL in the log doesn't result in the same output as the query in Ecto.

I've had a look at the code and I'm not sure what can be done about this. By the time dev_logger sees the parameter there is no longer any information to help it to understand the schema, so it's making the assumption that all 128 bit bitstrings are UUIDs, but that also matches 16 character strings.

@sh41 sh41 changed the title String converted to UUID 16 character string converted to UUID Jun 24, 2022
@sh41
Copy link
Contributor Author

sh41 commented Jun 24, 2022

And just to add another data point, it appears the same in Postgres:

iex(2)> Ecto.Adapters.SQL.query!(MyRepo, "SELECT $1::text" , ["abcdefghijklmnop"])

07:52:14.988 [debug] QUERY OK db=0.9ms decode=1.6ms
SELECT '61626364-6566-6768-696a-6b6c6d6e6f70'::text
%Postgrex.Result{
  columns: ["text"],
  command: :select,
  connection_id: 4598,
  messages: [],
  num_rows: 1,
  rows: [["abcdefghijklmnop"]]
}
iex(3)>

@fuelen
Copy link
Owner

fuelen commented Jun 24, 2022

It just happens that such binaries are valid UUID as well. We simply try to guess the Ecto type by Elixir type, as we don't have other metadata in telemetry. Such approach doesn't work well for all scenarios.

I assume, the issue will be resolved when elixir-ecto/ecto#3869 is done, so we wouldn't have to guess uuids in this library.

@sh41
Copy link
Contributor Author

sh41 commented Jun 24, 2022

Thanks @fuelen. That makes sense. 👍

@fuelen
Copy link
Owner

fuelen commented Feb 12, 2023

ecto_sql now has cast_params parameter in telemetry (starting from v3.9.2) which contains original values. In general, it is possible to combine params and cast_params somehow to understand that parameter in params is UUID, but I'm not sure if it is worth it, as this would require new API for Ecto.DevLogger.PrintableParameter protocol and thus major version bump.

@maxsalven
Copy link

Just an FYI, I ran into this today when using the string "America/New_York", a common time zone identifier.

@halostatue
Copy link
Contributor

ecto_sql now has cast_params parameter in telemetry (starting from v3.9.2) which contains original values. In general, it is possible to combine params and cast_params somehow to understand that parameter in params is UUID, but I'm not sure if it is worth it, as this would require new API for Ecto.DevLogger.PrintableParameter protocol and thus major version bump.

I just started playing with Ecto.DevLogger again and went through the issues and this paragraph has been mildly bugging me. This project is still in the 0.x.y phase of semantic versioning, in which case the x versions may signify breaking API changes. A stable API is not promised for 0.x.y versions, only for >= 1.0.0.

As I also store time zone strings in the database, I think it would be worthwhile seeing this improvement to prevent the America/New_York issue mentioned above.

@fuelen
Copy link
Owner

fuelen commented Dec 14, 2023

I wanted to make a major change and to initiate changes in ecto, so we can do precise logging https://groups.google.com/g/elixir-ecto/c/5AwUoaEuq4E/m/J9Kbr9FOBAAJ?pli=1 but seems like this won't be possible, only guessing.
About the particular issue, I think we can relatively easy fix UUIDs with the hack without making breaking changes - move converting uuid to readable string outside of Ecto.DevLogger.PrintableParameter, where we can compare values from params and cast_params. It is not a nice solution, but in general I see that Ecto.DevLogger.PrintableParameter abstraction is leaked.

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

No branches or pull requests

4 participants