Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore update is broken starting 5.5.1 #191

Closed
lm1 opened this issue Jan 19, 2018 · 11 comments
Closed

Firestore update is broken starting 5.5.1 #191

lm1 opened this issue Jan 19, 2018 · 11 comments
Assignees

Comments

@lm1
Copy link

lm1 commented Jan 19, 2018

Starting with firebase-admin 5.5.1 when performing an update within firestore transaction which contains both new nested fields and deletes some nested fields in the document, the new fields are silently dropped.

  • Operating System version: Win10
  • Firebase SDK version: 3.16.0
  • Library version: 5.5.1
  • Firebase Product: firestore

For example having a document which contains objects entries.G5VnUD and users.G5VnUD, but does not contain entries.LommiL nor users.LommiL the following operation results in deletion of entries.G5VnUD and users.G5VnUD, but the new nested fields are dropped on the floor without any warning.

transaction.update(docRef,
 { 'entries.LommiL':
   { time: 1516399412431,
     trainer: null,
     waiting: false,
     created: 1516399412431 },
  'users.LommiL': 1517342400000,
  'users.G5VnUD': {},
  'entries.G5VnUD': {}
});

Issue is still present in latest 5.8.1 but does not exist in 5.5.0

@google-oss-bot
Copy link

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@hiranya911
Copy link
Contributor

@schmidt-sebastian can you take a look?

@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented Jan 24, 2018

Hi! Thanks for sending this over. Firebase Admin 5.5.1 pulled in Firestore 0.10.x, which contains some changes to how we process nested maps, so this issue sounds pretty scary. It does, however, not reproduce for me:

ref.set({users: {G5VnUD: {foo: 'bar'}}, entries: {G5VnUD: {foo: 'bar'}}})
      .then(() => ref.get())
      .then(doc => {
        console.log(doc.data());
      })
      .then(() =>
        firestore.runTransaction(transaction => {
          transaction.update(ref, {
            'entries.LommiL': {
              time: 1516399412431,
              trainer: null,
              waiting: false,
              created: 1516399412431,
            },
            'users.LommiL': 1517342400000,
            'users.G5VnUD': {},
            'entries.G5VnUD': {},
          });

          return Promise.resolve();
        })
      )
      .then(() => ref.get())
      .then(doc => {
        console.log(doc.data());
      });

This prints the following for me on 0.10.2:

{ users: { G5VnUD: { foo: 'bar' } },
  entries: { G5VnUD: { foo: 'bar' } } }

and

{ users: { LommiL: 1517342400000, G5VnUD: {} },
  entries: 
   { LommiL: 
      { trainer: null,
        time: 1516399412431,
        created: 1516399412431,
        waiting: false },
     G5VnUD: {} } }

@lm1 Can you enable logging and send us your logs? You can pass console.log to here: https://github.com/googleapis/nodejs-firestore/blob/master/types/firestore.d.ts#L40

@schmidt-sebastian
Copy link
Contributor

Closing this issue for now as we can't reproduce this. Please ping us should this happen again.

@lm1
Copy link
Author

lm1 commented Jan 27, 2018

The same testcase fails for me when using deletion sentinels in place of empty object literals, i.e.:

  ref.set({users: {G5VnUD: {foo: 'bar'}}, entries: {G5VnUD: {foo: 'bar'}}})
  .then(() => ref.get())
  .then(doc => {
    console.log(doc.data());
  })
  .then(() =>
    firestore.runTransaction(transaction => {
      transaction.update(ref, {
        'entries.LommiL': {
          time: 1516399412431,
          trainer: null,
          waiting: false,
          created: 1516399412431
        },
        'users.LommiL': 1517342400000,
        'users.G5VnUD': admin.firestore.FieldValue.delete(),
        'entries.G5VnUD': admin.firestore.FieldValue.delete()
      });
      return Promise.resolve();
    })
  )
  .then(() => ref.get())
  .then(doc => {
    console.log(doc.data());
  });

this produces:

{ users: { G5VnUD: { foo: 'bar' } },
  entries: { G5VnUD: { foo: 'bar' } } }

and

{ users: {}, entries: {} }

Please re-open.

@Ziph0n
Copy link

Ziph0n commented Jan 29, 2018

I'm also facing this issue

My database structure:

users
|___ id1
       |___ data
                   |___ left
                             |___ thing1 = 2
                             |___ thing1 = 20
                   |___ pro
                             |___ subscribed = true
       |___ ...

If I'm running this:

admin.firestore().collection("users").doc("id1").update({
    data: {
        pro: {
            subscribed: false
        }
    }
});

The "new" database structure is:

users
|___ id1
       |___ data
                   |___ pro
                             |___ subscribed = false
       |___ ...

I'm using firebase-admin 5.8.1

@lm1
Copy link
Author

lm1 commented Jan 29, 2018

@Ziph0n I think this behavior is actually expected, use { ['data.pro.subscribed']: false } for nested field update.
I'm only seeing the issue with deletion sentinel in play.

@Ziph0n
Copy link

Ziph0n commented Jan 29, 2018

@lm1 Indeed, thank you.

The Firebase team might want to update their documentation. They indeed mention the "dot notation" but isn't present in the example below: https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects

@schmidt-sebastian
Copy link
Contributor

The Firebase team might want to update their documentation. They indeed mention the "dot notation" but isn't present in the example below: https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects

It's part of the update call to update the value of the field favorites.color.

@schmidt-sebastian
Copy link
Contributor

This is part of the 0.11.2 Firestore release: https://github.com/googleapis/nodejs-firestore/releases/tag/v0.11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants