Skip to content

Commit

Permalink
Single source for snowflake ids
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel authored and jsvgoncalves committed Nov 8, 2024
1 parent e39758f commit 977f78d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bw2data/revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from typing import Any, Optional, Sequence, TypeVar

import deepdiff
from snowflake import SnowflakeGenerator as sfg

from bw2data.snowflake_ids import snowflake_id_generator
from bw2data.backends.proxies import Activity, Exchange
from bw2data.backends.schema import ActivityDataset, ExchangeDataset, SignaledDataset
from bw2data.backends.utils import dict_as_activitydataset, dict_as_exchangedataset
Expand Down Expand Up @@ -186,7 +186,7 @@ def generate_metadata(
) -> dict[str, Any]:
metadata = metadata or {}
metadata["parent_revision"] = parent_revision
metadata["revision"] = revision or next(sfg(0))
metadata["revision"] = revision or next(snowflake_id_generator)
metadata["authors"] = metadata.get("authors", "Anonymous")
metadata["title"] = metadata.get("title", "Untitled revision")
metadata["description"] = metadata.get("description", "No description")
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_node_edge_events.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import json

import pytest
from snowflake import SnowflakeGenerator as sfg

from bw2data import get_node
from bw2data.backends.schema import ExchangeDataset
from bw2data.database import DatabaseChooser
from bw2data.project import projects
from bw2data.tests import bw2test
from bw2data.snowflake_ids import snowflake_id_generator


@bw2test
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_node_revision_apply_create():
database = DatabaseChooser("db")
database.register()

revision_id = next(sfg(0))
revision_id = next(snowflake_id_generator)
revision = {
"data": [
{
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_node_revision_apply_delete():
node.save()
assert len(database) == 1

revision_id = next(sfg(0))
revision_id = next(snowflake_id_generator)

revision = {
"data": [
Expand Down Expand Up @@ -261,7 +261,7 @@ def test_node_revision_apply_update():
node = database.new_node(code="A", name="A", location="kalamazoo")
node.save()

revision_id = next(sfg(0))
revision_id = next(snowflake_id_generator)

revision = {
"data": [
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_node_revision_apply_activity_database_change():
node.new_edge(input=node, type="production", amount=1.0).save()
assert len(node.exchanges()) == 2

revision_id = next(sfg(0))
revision_id = next(snowflake_id_generator)

num_revisions_before = len([
fp
Expand Down Expand Up @@ -459,7 +459,7 @@ def test_node_revision_apply_activity_code_change():
node.new_edge(input=node, type="production", amount=1.0).save()
assert len(node.exchanges()) == 2

revision_id = next(sfg(0))
revision_id = next(snowflake_id_generator)

num_revisions_before = len([
fp
Expand Down Expand Up @@ -660,9 +660,9 @@ def test_node_revision_apply_activity_copy():

projects.dataset.set_sourced()

revision_id_1 = next(sfg(0))
revision_id_2 = next(sfg(0))
revision_id_3 = next(sfg(0))
revision_id_1 = next(snowflake_id_generator)
revision_id_2 = next(snowflake_id_generator)
revision_id_3 = next(snowflake_id_generator)

num_revisions_before = len([
fp
Expand Down

0 comments on commit 977f78d

Please sign in to comment.