yesodweb / yesodweb/persistent

discoverEntities discovers entities for the wrong backend

Open
#1,578 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

discoverEntities returns all entities that are in scope, regardless of the backend they use. This can cause problems with mkPersistWith, which uses the discovered entities to infer which fields are references: if a model defines a field with a name that happens to overlap the name of an entity on another backend, the field will be incorrectly inferred as a reference.

We worked around this downstream by filtering the entity types considered by discoverEntities based on their PersistEntityBackend instance.

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 mkPersistWith and the discoverEntities behavior in persistent/Database/Persist/TH/Internal.hs, especially the linked code around lines 901 and 3414. Compare the existing downstream filtering of entity types by PersistEntityBackend. Done means discoverEntities only returns in-scope entities for the relevant backend, preventing cross-backend name collisions from being inferred as references.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.