Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/datajoint/heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ def set_primary_key(self, primary_key):
(dict(self.attributes[name].todict(), in_key=True) for name in primary_key),
(dict(self.attributes[name].todict(), in_key=False) for name in self.names if name not in primary_key),
),
table_info=self.table_info,
lineage_available=self._lineage_available,
)

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_pk_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
primary keys in join operations.
"""

from types import SimpleNamespace

from datajoint.adapters import PostgreSQLAdapter
from datajoint.heading import Heading


Expand Down Expand Up @@ -205,3 +208,14 @@ def test_b_determines_a_ordering(self):
assert names.index("x") < names.index("z")
# y should be secondary (demoted from A's PK)
assert "y" in result.secondary_attributes


class TestSetPrimaryKey:
"""Tests for Heading.set_primary_key."""

def test_keeps_the_adapter_for_a_later_rename(self):
"""A rename after set_primary_key (as dj.U & table does) quotes for the connection's backend."""
heading = make_heading(["a"], ["b"])
heading.table_info = {"conn": SimpleNamespace(adapter=PostgreSQLAdapter())}
renamed = heading.set_primary_key(["b"]).select([], rename_map={"c": "b"})
assert renamed.attributes["c"].attribute_expression == '"b"'