Skip to content

Commit

Permalink
DEV-941: use six.ensure_str to fix tag mismatch issue (#373)
Browse files Browse the repository at this point in the history
* DEV-941: use six.ensure_str to fix tag mismatch issue
  • Loading branch information
kulgan committed Nov 5, 2021
1 parent 924fc8a commit 22756bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,4 +1,5 @@
language: python
dist: bionic

python:
- 2.7
Expand All @@ -11,7 +12,7 @@ addons:
postgresql: "13"
apt:
sources:
- sourceline: deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main 13
- sourceline: deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main 13
key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
packages:
- postgresql-13
Expand Down
16 changes: 13 additions & 3 deletions gdcdatamodel/models/versioning.py
@@ -1,6 +1,7 @@
import os
import uuid

import six
from sqlalchemy import and_, event, select

UUID_NAMESPACE_SEED = os.getenv("UUID_NAMESPACE_SEED", "86bb916a-24c5-48e4-8a46-5ea73a379d47")
Expand All @@ -16,7 +17,7 @@ class TagKeys:
def __generate_hash(seed, label):
namespace = UUID_NAMESPACE
name = "{}-{}".format(seed, label)
return str(uuid.uuid5(namespace, name))
return six.ensure_str(str(uuid.uuid5(namespace, name)))


def compute_tag(node):
Expand All @@ -26,8 +27,17 @@ def compute_tag(node):
Returns:
str: computed tag
"""
keys = [node.node_id if p == "node_id" else node.props[p] for p in node.tag_properties]
keys += sorted([p.dst.tag or compute_tag(p.dst) for p in node.edges_out if p.label != "relates_to"])
keys = [
six.ensure_str(node.node_id if p == "node_id" else node.props[p])
for p in node.tag_properties
]
keys += sorted(
[
six.ensure_str(p.dst.tag or compute_tag(p.dst))
for p in node.edges_out
if p.label != "relates_to"
]
)
return __generate_hash(keys, node.label)


Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -9,6 +9,7 @@
setup_requires=["setuptools_scm<6"],
packages=find_packages(),
install_requires=[
"six~=1.15",
"pytz~=2020.1",
"graphviz>=0.4.10,<0.17",
"jsonschema~=3.2",
Expand Down
3 changes: 2 additions & 1 deletion test/test_node_tagging.py
@@ -1,7 +1,7 @@
import pytest
from psqlgraph import PsqlGraphDriver

from gdcdatamodel.models import basic # noqa
from gdcdatamodel.models import basic, versioning # noqa
from test.helpers import create_tables, truncate


Expand Down Expand Up @@ -60,3 +60,4 @@ def test_1(create_samples, bg, node_id, tag, version):
node = bg.nodes().get(node_id)
assert node.tag == tag
assert node.ver == version
assert versioning.compute_tag(node) == node.tag

0 comments on commit 22756bc

Please sign in to comment.