yesodweb / yesodweb/persistent

Camel-case field names cause failed reads

Open
#1,054 0 comments 1 reaction 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

It appears at least for the mongo backend that using camel case for field names leads to no functionality. A full example is on my github but the gist is:

share
    [mkPersist mongoSettings]
    [persistLowerCase|

BThing
    anyInnerRecordWithCamelFieldsFails Int
    deriving Show
AThing
    record_field BThing
    deriving Show
|]

main :: IO ()
main =
    withMongoDBConn
        "myDatabaseName"
        "localhost"
        (PortNumber 27017)
        Nothing
        2000
        (runMongoDBPool
             master
             (do athing <- insert (AThing (BThing 1))
                 liftIO $ print athing
                 athingEnt <- selectList [] [] :: Action IO [Entity AThing]
                 liftIO $ print (map entityVal athingEnt)
                 return ()))

EDIT: Sorry, submitted too fast. Executing the above we get:

docker run --rm -d -p 27017:27017 mongo:3.6
cabal run
Up to date
MongoKey {unMongoKey = 5e69ebd7ccf0323fd5000000}
MongoPersist: PersistMarshalError "AThing: Couldn't parse field `record_field` from table `a_thing`. Couldn't parse field `anyInnerRecordWithCamelFieldsFails` from table `b_thing`. Failed to parse Haskell type `Int`; expected integer from database, but received: PersistNull. Potential solution: Check that your database schema matches your Persistent model definitions. for doc: [ _id: 5e69ebd7ccf0323fd5000000, record_field: [ any_inner_record_with_camel_fields_fails: 1]]"

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 by reproducing the example from the issue with the MongoDB backend and the linked toy-mongo-and-persistent project. Compare the persisted document's snake_case fields with the Haskell camel-case fields and trace the read path. Done means inserting and selecting the example records returns their original Int values instead of PersistNull.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.