Skip to content

New document ID not unique after fork #346

@jdsutton7

Description

@jdsutton7

Originally reported here: firebase/firebase-admin-python#548

If firebase_admin is imported before os.fork(), auto-generated document IDs are repeated causing data to be overwritten.

Environment details

  • OS type and version: Linux Mint 20
  • Python version: Python 3.6.13
  • pip version: pip 21.1
  • google-cloud-firestore version: 2.1.0

Steps to reproduce

Import firebase_admin, fork, create firestore client, write a new document.

Code example

#!/usr/bin/env python3.6

import os
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

pid = os.fork()

cred = credentials.Certificate('service_account.json')
firebase_admin.initialize_app(cred)

client = firestore.client()

if pid == 0:
    reference = client.collection('Test').document()
    reference.set({'a': 'b'})

    print('Child: ' + reference.id)
else:
    reference = client.collection('Test').document()
    reference.set({'a': 'c'})

    print('Parent: ' + reference.id)

Output:

Child: TCsit2S0VQgvqm0aHNTc
Parent: TCsit2S0VQgvqm0aHNTc

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: firestoreIssues related to the googleapis/python-firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions