yesodweb / yesodweb/persistent

update/upsert sets a String field with "0"

Open
#1,007 4 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

Hi,

Up on record update/upsert (if update) new value is discarded and column value in db gets "0".

 CREATE TABLE `t1` (
  `pk` int(11) NOT NULL,
  `vl` varchar(200) NOT NULL,
  PRIMARY KEY (`pk`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
:set +m
:set -XQuasiQuotes
:set -XOverloadedStrings
:set -XTemplateHaskell
:set -XTypeFamilies
:set -XGADTs
:set -XMultiParamTypeClasses
:set -XGeneralizedNewtypeDeriving

import Database.Persist
import Control.Monad.Logger
import Data.Pool
import Database.Persist.TH
import Database.Persist.MySQL

cinf = mkMySQLConnectInfo "localhost" "root" "root" "db1"
p2 <- runNoLoggingT (createMySQLPool cinf 2  :: NoLoggingT IO (Pool SqlBackend))

$(mkPersist sqlSettings  ([persistLowerCase|
MyT8 sql=t1 
  uid Int sql=pk
  value String sql=vl
  Primary uid
  UniqueUid uid
  deriving Show Read Eq Ord  |]));

# runSqlPool (upsert  (MyT8 11 "xxx") [MyT8Value +=. "yyy"]) p2
Entity {entityKey = MyT8Key {unMyT8Key = 11}, entityVal = MyT8 {myT8Uid = 11, myT8Value = "xxx"}}
# runSqlPool (upsert  (MyT8 11 "xxx") [MyT8Value +=. "yyy"]) p2
Entity {entityKey = MyT8Key {unMyT8Key = 11}, entityVal = MyT8 {myT8Uid = 11, myT8Value = "0"}}

Checking db

mysql> select * from t1 where pk = 11;
+----+----+
| pk | vl |
+----+----+
| 11 | 0  |
+----+----+
1 row in set (0.00 sec)


GHCI 8.6.5 windows 10 and mysql 5.6.39 on docker

mysql-haskell-0.8.4.2
persistent-2.9.2

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 running the supplied GHCi reproduction against the shown MySQL schema, comparing the initial insert with the repeated upsert. Trace the persistent upsert path for the String field and add coverage for this case; done means the repeated operation no longer stores "0" unexpectedly in t1.vl.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, mysql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.