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

Associated module is not an Ecto schema #4371

Closed
paulo-silva opened this issue Feb 9, 2024 · 7 comments
Closed

Associated module is not an Ecto schema #4371

paulo-silva opened this issue Feb 9, 2024 · 7 comments

Comments

@paulo-silva
Copy link

Elixir version

1.16.0

Database and Version

PostgreSQL 15.2

Ecto Versions

3.11.1

Database Adapter and Versions (postgrex, myxql, etc)

postgrex 0.17.4

Current behavior

While bumping elixir on my project, I noticed while compiling a warning like:

warning: invalid association `selection_master` in schema App.Schemas.Schema: associated module App.Schemas.AssocSchema is not an Ecto schema

Checking this previous issue: #4293 - elixir 1.16 was meant to fix this problem, but some devs are still experiencing this problem.

Expected behavior

This warn should not happen, like it wasn't when using previous versions of elixir.

@josevalim
Copy link
Member

Hi @paulo-silva. We need a mechanism to reproduce the warning, otherwise there isn't much we can do about it. :(

@paulo-silva
Copy link
Author

Hi @paulo-silva. We need a mechanism to reproduce the warning, otherwise there isn't much we can do about it. :(

@josevalim that makes sense, I'll try to reproduce it in a project example

@paulo-silva
Copy link
Author

@josevalim I tried to reproduce that in a project example, but I'm unable to; I guess the issue is related to the project size. Is there any chance we can huddle and I can show you the issue in the real project?

I tried the strategy proposed in slack ecto channel as a temp workaround, but I started getting deadlocks

@nulian
Copy link

nulian commented Feb 20, 2024

After some puzzling with this same error for me it was caused by having a module attribute reference to a different schema. Though most of the times doing that doesn't seem to cause any issues but in 1 case it caused the same error for me. Giving a warning everytime trying to build it.

@organization_role_id_admin OrganizationRole.admin_role_id()

Schema gets warning from has_many in organizations -> organization_memberships while this memberships references a third schema with the module attribute.

I guess because it waits for the belongs_to to be ready and the organization waits for the has_many to be ready causing the issue.

@nulian
Copy link

nulian commented Feb 20, 2024

I saw another difference in our project from before the refactor that the has_many was removed from organization_role -> organization_memberships

When I readd the has_many it will solve the warning.

I guess because it is referenced in the has_many it knows to wait for it or something and no longer give the compile warning.

@JoeriDijkstra
Copy link

After changing @organization_role_id_admin OrganizationRole.admin_role_id() to a static value it seems to work great: @organization_role_id_admin "foobar"

so probably some race condition in the compiler like nulian said.

@josevalim
Copy link
Member

Closing it as #4293 was reopened.

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

No branches or pull requests

4 participants