question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data loss when object passed into createNode with string "7up"

See original GitHub issue

Description

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. Screenshot 2019-12-26 at 11 57 23

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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
deanccommented, Dec 26, 2019

@vladar that was the issue. Thanks. I had tried upgrading gatsby-cli earlier, but didn’t realise my dependencies were out of date.

1reaction
vladarcommented, Dec 26, 2019

Looks like there was a bug in gatsby 2.18.12. In short, sanitizeNode was removing keys with identical values. This bug was fixed in gatsby 2.18.13 via https://github.com/gatsbyjs/gatsby/pull/20039

Please try upgrading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

One class property (of many) is lost after object passed back to ...
One constructor File_Attachment(int Attachment_ID) creates an instance of the class, populated with data from a single database row. The second ...
Read more >
Storing Data in Node-Red Variables
Learn how to store data in node-red context,flow and global variables. ... Node-red nodes pass the msg object between nodes.
Read more >
Determining Object Type - Visual Basic | Microsoft Learn
Visual Basic provides two means of determining which type of object is stored in an object variable: the TypeName function and the TypeOf....
Read more >
Earth Engine Objects - Google Developers
String () container to be sent to Earth Engine: ... To pass parameters by name, pass in a JavaScript object in which the...
Read more >
How to pass Map<String, String> to a method ? — oracle-tech
I have a method which expects Map<String,Object> as a parameter.How to pass Map<String,String> to that method?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found