Session Not Loaded #Ecto.Association.NotLoaded<association :sessions is not loaded>
Open
Nobody has claimed this yet.
chore
T25m
technical
- Dominant language
- Dart
- Stars
- 152
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
Invoking Ctx.get_person! fails because the session is not pre-loaded
The people schema has the following association:
has_many :sessions, App.Ctx.Session
We want this association.
But not having the the :session pre-loaded means a bunch of tests are failing ... 😞
1) test people update_person/2 with invalid data returns error changeset (App.CtxTest)
test/app/ctx_test.exs:184
** (UndefinedFunctionError) function App.Ctx.Person.fetch/2 is undefined (App.Ctx.Person does not implement the Access behaviour)
code: person = person_fixture()
stacktrace:
(app) App.Ctx.Person.fetch(%App.Ctx.Person{__meta__: #Ecto.Schema.Metadata<:built, "people">, email: nil, email_hash: nil, familyName: nil, givenName: nil, id: nil, inserted_at: nil, key_id: nil, locale: nil, password_hash: nil, picture: nil, sessions: #Ecto.Association.NotLoaded<association :sessions is not loaded>, status: nil, tag: nil, updated_at: nil, username: nil, username_hash: nil}, "email")
(elixir) lib/access.ex:267: Access.get/3
(app) lib/app/ctx/person.ex:28: App.Ctx.Person.changeset/2
(app) lib/app/ctx.ex:251: App.Ctx.create_person/1
test/app/ctx_test.exs:138: App.CtxTest.person_fixture/1
test/app/ctx_test.exs:185: (test)
Finished in 0.4 seconds
45 tests, 1 failure, 44 excluded
Randomized with seed 123741
Todo
- add
Repo.preload([:session])toCtx.get_person!/1 - debug ...
Note: this only happens when I attempt to actually hash the email address 🙄
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with test/app/ctx_test.exs and the failing person_fixture stack trace, then read lib/app/ctx.ex and lib/app/ctx/person.ex around get_person!/1 and changeset/2. Reproduce the failure and verify the session association behavior; done means the affected tests no longer fail when email hashing runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100