dwyl / dwyl/app

Session Not Loaded #Ecto.Association.NotLoaded<association :sessions is not loaded>

Open
#251 1 comment 0 reactions 0 assignees View on GitHub

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]) to Ctx.get_person!/1
  • debug ...

Note: this only happens when I attempt to actually hash the email address 🙄

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.