Cyclic dependencies in Ecto/Phoenix applications arising from associations

My application started showing errors in the VS Code problems tab (from the Elixir language server) telling me about cyclic dependencies.

The cyclic dependencies show as cycles between Ecto schema modules, and I wonder if they arise from belongs_to/has_many pairings in 1 : N relations.

In general, the dependencies between contexts and schemas generates long cycles (10-11 steps).

Is there a general guide line on cyclic module dependencies in this setting? Is it okay to have cycles in this case? Should I investigate further?

They do not cause issues, this is 100% allowed.

Can you show some of these modules? Are you using require or use in these modules?

No requires and no custom macros (99% sure).

Running mix clean generally fixes it for some compiler runs.

It is hard to show modules because the bug is very intermittent. It shows as CompileError in a specific Ecto.Schema module, but if I save the module it shows in a different module.

For example, I got this error message:

(CompileError) cannot define module AppWeb.AdminCompanyView because it is currently being defined in lib/app_web/views/admin_company_view.ex:1

Stacktrace:
  │ (stdlib 3.15) erl_eval.erl:685: :erl_eval.do_apply/6

And this was a first, it never showed up on this module.

And this error came from the file lib/app_web/views/admin_company_view.ex itself, which may be that the compiler is compiling the file twice? Not an expert on the whole compilation pipeline.

You should probably just delete the .elixir_ls directory and see if that fixes it. :person_shrugging: