FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(heading): keep table_info in set_primary_key so a later rename quotes for the backend by mayuriphad · Pull Request #1643 · datajoint/datajoint-python · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions src/datajoint/heading.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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"'

Back | FazBrowse Home | New Git URL