Data loss when object passed into createNode with string "7up"
See original GitHub issueDescription
I’m using my own plugin to import data from firestore into gatsby. Source code here: https://github.com/deanc/gatsby-source-firestore/tree/test
When passing in the a certain object to createNode, the name
field’s value when set to 7up
is lost and becomes null
.
Steps to reproduce
I’ve tried to boil this down to a test-case. I’ve tried passing the exact same params into createNode manually in a fresh gatsby, but I can’t reproduce it there. I can only reproduce it in my application. Therefore steps to reproduce are very difficult.
I am 100% certain that the field name
is set in my data to the string 7up
. I have verified this editing the createNode statement in my node_modules
directly.
The statement:
createNode(Object.assign({}, nodeData, nodeMeta));
nodeData
:
{ created: Timestamp { _seconds: 1438014230, _nanoseconds: 0 },
views: 570,
slug: '7up',
active: 1,
name: '7up',
type: 'product',
updated: Timestamp { _seconds: 1438014230, _nanoseconds: 0 },
id: 50,
nameTwo: '7up' }
nodeMeta
:
{ id: 'bh0UWRLmzZkmHAJUwQOR',
parent: null,
children: [],
internal:
{ type: 'Item',
content:
'{"created":{"_seconds":1438014230,"_nanoseconds":0},"views":570,"slug":"7up","active":1,"name":"7up","type":"product","updated":{"_seconds":1438014230,"_nanoseconds":0},"id":50,"nameTwo":"7up"}',
contentDigest: '663b0f201d29ac315961f9b111612f33' } }
When passing the above params manually in a fresh gatsby install, it works. Tried 3 times in a row.
Expected result
The allItem
graphql object should have keys name
and slug
with values 7up
.
Actual result
Instead 9/10 times when running a full cache clear and yarn start
the name
field’s value is null
. Very occasionally the slug
is null
too.
Environment
System:
OS: macOS 10.15.2
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Shell: 5.0.11 - /usr/local/bin/bash
Binaries:
Node: 10.16.3 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 79.0.3945.88
Firefox: 70.0
Safari: 13.0.4
npmPackages:
gatsby: ^2.18.8 => 2.18.8
gatsby-firesource: https://github.com/deanc/gatsby-source-firestore#test => 2.0.0
gatsby-image: ^2.2.34 => 2.2.34
gatsby-plugin-layout: ^1.1.18 => 1.1.18
gatsby-plugin-manifest: ^2.2.31 => 2.2.31
gatsby-plugin-offline: ^3.0.27 => 3.0.27
gatsby-plugin-react-helmet: ^3.1.16 => 3.1.16
gatsby-plugin-sass: ^2.1.26 => 2.1.26
gatsby-plugin-sharp: ^2.3.5 => 2.3.5
gatsby-plugin-styled-components: ^3.1.16 => 3.1.16
gatsby-source-filesystem: ^2.1.43 => 2.1.43
gatsby-transformer-sharp: ^2.3.7 => 2.3.7
npmGlobalPackages:
gatsby-cli: 2.8.22
Conclusion
I have 70 other items in my firestore database. This only happens when the name field is set to 7up
. I just changed it to 6up
and ran the rm -rf .cache/; yarn start
command 5 times, and the name
field was correctly populated.
My guesses are either this is deep in the depths of gatsby there is some transformation happening on that string and somehow it’s thinking it’s some form of number representation. Or, there is some kind of clash between this and existing records.
All ideas welcome, and happy to debug further.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
@vladar that was the issue. Thanks. I had tried upgrading gatsby-cli earlier, but didn’t realise my dependencies were out of date.
Looks like there was a bug in
gatsby 2.18.12
. In short,sanitizeNode
was removing keys with identical values. This bug was fixed ingatsby 2.18.13
via https://github.com/gatsbyjs/gatsby/pull/20039Please try upgrading.