revati
Hello, i have fallowing code in my tests:
source = %MyModule{} |> Repo.insert!()
new = Repo.get!(MyModule, source.id)
assert new.id == source.id
but oddly enough it throws an error, as you can see ids are slightly different.
Assertion with == failed
code: assert new.id() == source.id()
left: "3f3fd9a2-3f69-463e-3f3f-153f34003f3f"
right: "85c9d9a2-a969-463e-a8d5-15f834009ebc"
MyModule schema uses following base schema
defmodule Stats.Schema do
defmacro __using__(_) do
quote do
use Ecto.Schema
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
end
end
end
How come ecto can find the row in DB by id, but later when comparing those ids, they mismatch?
is it some binary encoding problem?
Im use ecto: 2.2.10, mariaex: 0.8.4, mysql: 5.7.20
Thanks
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jeremyjh
Can you please provide the actual schema definition and migration file?
peerreynders
Just an aside; possibly relevant:
1:
2:
3: TIL: Ecto reading after writes:
5.7.1 was released 2013-04-23. According to GUID/UUID Performance Breakthrough
i.e. pre-8.0 UUIDs could be problematic/high maintenance.
See also:
+1
revati
Migration:
Schema:
peerreynders
I’m guessing that the above simply, implicitly adds a
In the SQL shell, do a
DESCRIBE sources;and see what the type of theidcolumn actually is. Given Ecto’s documentation I would expect abinary(16)for a UUID column - a standard:idwill be some kind of integer.If the
idcolumn is the wrong type, I’d start withand go from there - i.e. see if it works or if it simply changes the problem.
only has an effect on
Schemasthatuseit - it doesn’t impact the migration at all - so there needs to be some kind of hint in the migration that the table is dealing with a:binary_idinstead of a:idtype.revati
i completely forget to add mysql schema. sorry.
in my config i also have:
peerreynders
Have your tried:
What is not clear is whether
newactually originates from the same record that was created by the previousRepo.insert!. If there are other records in the table,newcould be an entirely different record.Some experiments with iEX and the SQL shell could shed some light on that:
3f3fd9a2-3f69-463e-3f3f-153f34003f3f)85c9d9a2-a969-463e-a8d5-15f834009ebc)This was never resolved:
revati
Didn’t quite catch. Its internal Ecto function
Repo.get!which retrieves a new record by id. It isn’t in any way tied to the previous source record. The table is empty before that and id column is a primary index (must be unique), so in either case, there couldn’t be duplicate ids in the table.tried and this works fine
revati
I updated MySQL to
8.0.11version, but there still is a problemrevati
https://github.com/elixir-ecto/ecto/issues/2602
peerreynders
I’d go even further. Once you insert a record in
iEX, use the MySQL shell to show you what value in theidcolumn actually is. Something like:That really is the only way to know what was actually written to the database as the UUID data can just as easily be compromised on the
Repo.allreturn trip.The fundamental issue here is that you have shown that in your environment the result of the query cannot necessarily be trusted. Given that there is only one record in the table, multiple distinct IDs seem to be returning the same record which can only have one ID. So there could be a whole set of ID values capable of selecting this one record.
You write the record with ID A and you retrieve with ID A something with ID B.
So at this point superficially it looks like ID B is in the database but it could be corrupted on read, so ID A could still exist in the database.
Now you retrieve with ID B and get something with ID B.
Given that it seems that the ID value is being corrupted somewhere, there is the possibility that sometimes ID related queries will not work (depending on the nature of the corruption).
To narrow this down you should create a minimal ecto-only project with a single table in a new database with an UUID column and a second (string) column for information that lets you uniquely identify each record created for inspection.
Set up a unit test similar to the one you have. You may have to run the test repeatedly until it fails (or some max is reached) - sometimes these type of defects are intermittent.
Once you have a setup that consistently fails in your environment, put the project up on GitHub and reference the repository in the issue. That way somebody else can easily try it in their (MySQL) environment to see if the problem behaviour persists.