Skip to content

Instantly share code, notes, and snippets.

@paulanthonywilson
Last active October 24, 2015 10:59
Show Gist options
  • Save paulanthonywilson/b0b5aeffc7a295d17d92 to your computer and use it in GitHub Desktop.
Save paulanthonywilson/b0b5aeffc7a295d17d92 to your computer and use it in GitHub Desktop.

UPDATE - Not an ecto problem

"A good bug, I mean a really good, pound-your-head-on-the-desk-for-a-week bug, is exactly like a magic trick in that something impossible appears to be happening." - Steven Frank via Daring Fireball

tl;dr The issue was that there was a Beam file for my Ecto model/struct in the root of project directory

It was a compilation timing issue. Some files were being compiled before web/models and some afterwards. Somehow an old beam file Elixir.ProjectStatus.EmailRecipient.beam had been compiled into the project root, on the 2015-06-25 with Ecto 0.12.0; in this version of Ecto the __meta__.source was a binary. The clue which, I'd seen but didn't know what to do with, was that the warning that the module was being redefined.

Compiled lib/project_status/project_recipients.ex
Compiled lib/project_status/repo.ex
Compiled web/models/custom_encoders.ex
web/models/email_recipient.ex:1: warning: redefining module ProjectStatus.EmailRecipient
Compiled web/channels/user_socket.ex
Compiled web/templates/project/status_email_dates.ex

Thanks to José Valim for spending 30 minutes tracking the issue down, on a Friday evening.

How it looked to me

I’m experiencing a very strange issue atm, which is one particular model’s __meta__ is a binary, rather than a tuple in some modules / functions after a fresh compile. If I modify the file and recompile the issue goes away. This affects inserts as the model no longer matches

def insert(repo, %{source: {prefix, source}}, params, _autogenerate, returning, opts) do

in Ecto.Adapters.SQL. I can’t figure out what’s going on; I figure it might be some kind of library clash, but I can’t find anything acking through the dependencies. Upgrading Ecto doesn’t seem to help, but fwiw my mix.lock is https://github.com/CultivateHQ/project_status/blob/master/mix.lock

It may (or may not) be a coincidence that this is currently the only record being used within a GenServer. (In experiments the source comes through as a binary rather than a tuple in other places, though.)

This is my current workaround https://github.com/CultivateHQ/project_status/blob/master/lib/project_status/project_recipients.ex#L71-L83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment