maddyblue/goon

Reusing entity cause slice values to be appended

yuichi1004 opened this issue · 2 comments

I found that when we fetch slice values from cache, goon appends the values into existing slice. Instead of appending values, goon should replace the slice.

Test to reproduce:
yuichi1004@ab412e6

Test Result:

$ go test -v -run Migration  ./
=== RUN   TestMigration
INFO     2018-04-28 09:43:06,511 devappserver2.py:105] Skipping SDK update check.
WARNING  2018-04-28 09:43:06,511 devappserver2.py:121] DEFAULT_VERSION_HOSTNAME will not be set correctly with --port=0
WARNING  2018-04-28 09:43:06,566 simple_search_stub.py:1196] Could not read search indexes from /var/folders/5j/2bmf8d2d3xgb9lmttlptxvm8p49fjs/T/appengine.testapp.01099286/search_indexes
INFO     2018-04-28 09:43:06,568 api_server.py:308] Starting API server at: http://localhost:51010
INFO     2018-04-28 09:43:06,638 dispatcher.py:255] Starting module "default" running at: http://localhost:51011
INFO     2018-04-28 09:43:06,640 admin_server.py:146] Starting admin server at: http://localhost:51013
--- FAIL: TestMigration (4.48s)
        goon_test.go:994: MC-false > Expected 1 car! Got: 2
FAIL
exit status 1
FAIL    github.com/yuichi1004/goon      4.501s

Note that we have extra cars on the above test.

Appending without reset should be correct because this is what the datastore package does.

See the following quotes from the docs:

func Get

The values of dst's unmatched struct fields are not modified, and matching slice-typed fields are not reset before appending to them. In particular, it is recommended to pass a pointer to a zero valued struct on each Get call.

func RunInTransaction

Since f may be called multiple times, f should usually be idempotent. datastore.Get is not idempotent when unmarshaling slice fields.

i never know this. thanks for your clarification. let me close this since it is as expected.