Skip to content

Automatic (TH) PathPiece generation is poorly documented, and confusing #649

@tebello-thejane

Description

@tebello-thejane

The documentation for mkPersist says

Create data types and appropriate PersistEntity instances for the given EntityDefs. Works well with the persist quasi-quoter.

I'm struggling to understand why it also creates PathPiece instances. In particular, I have hit a confusing issue where, with more than two tables being defined, using an enum type (whose instances where generated via derivePersistField) in the one table causes the compiler to complain that the data type does not have the appropriate path-pieces instances, but enums in another table do not cause the same error.

The source code for the module reads

-- | declare the key type and associated instances
-- @'PathPiece'@, @'ToHttpApiData'@ and @'FromHttpApiData'@ instances are only generated for a Key with one field
mkKeyTypeDec :: MkPersistSettings → EntityDef → Q (Dec, [Dec])

What does this even mean?? Note that my project does not use Yesod (yet), so I'm finding it difficult to justify creating PathPiece and *HttpApiData instances just to satisfy the compiler when there aren't any actual paths in the code base, or any other hint of HTTP.

On a possibly-related note, declaring DeriveGeneric and DeriveAnyClass as default extensions in my project causes mkPersist to blow up and start complaining about missing Generic instances. That is, I guess this might be a weird extensions issue, but right now my guesses are worthless.

If necessary, I can try and create a minimal example producing the issue. But I'm hoping this rings a bell and has been encountered by someone else before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions