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

Repo.preload looses prefix when nested preloads are requested. #3441

Closed
hickscorp opened this issue Oct 11, 2020 · 3 comments
Closed

Repo.preload looses prefix when nested preloads are requested. #3441

hickscorp opened this issue Oct 11, 2020 · 3 comments

Comments

@hickscorp
Copy link

hickscorp commented Oct 11, 2020

Environment

  • Elixir version (elixir -v): 1.10.4
  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): Postgres 12
  • Ecto version (mix deps): 3.5.1
  • Database adapter and version (mix deps): Ecto SQL 3.5
  • Operating system: Xubuntu 20.04

Current behavior

We are working on an app that uses multi-tenancy.

At some point, deep in our function call tree, we're trying to preload stuff. The weirdest thing happens:

  • This works: c |> Repo.preload(:agent)
  • This works: c |> Repo.preload(:notifier)
  • This does not work: c |> Repo.preload(:agent, :notifier) - Ecto tries to find the notifier association back in the public prefix...
  • But then this works: c |> Repo.preload([:agent:, :notifier], prefix: "whatever")
  • And also this works: c |> Repo.preload(:agent) |> Repo.preload(:notifier)

Expected behavior

Ecto should stay on the prefix for the structure passed on the first argument of preload.

Notes

Our Repo.default_options looks in process storage to find which prefix to work on. We are wondering whether Repo.preload is trying to either bypass default_options past one preload, or spawn other processes (which won't inherit storage from current process, and therefore won't have the prefix set when calling Repo.default_options). Which one is it? :)

Also something worth mentioning, when the bug occurs all bindings from my IEX shell are lost.

@josevalim
Copy link
Member

Can you please fill in the issues template?

@hickscorp
Copy link
Author

Done @josevalim

@hickscorp
Copy link
Author

Well that was fast. Thanks @josevalim !

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

2 participants