Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-105 fix /definition bug #170

Merged
merged 3 commits into from
Oct 9, 2023
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.8.10] - 2023-10-10

### Fixed

- Bug with `/definition` route for part tables [#170](https://github.com/datajoint/pharus/pull/170)

## [0.8.9] - 2023-10-02

### Added
Expand Down
14 changes: 10 additions & 4 deletions pharus/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ def _get_table_definition(
local_values[schema_name] = dj.VirtualModule(
schema_name, schema_name, connection=connection
)
return getattr(local_values[schema_name], table_name).describe()
return _DJConnector._get_table_object(
local_values[schema_name], table_name
).describe()

@staticmethod
def _insert_tuple(
Expand All @@ -319,7 +321,9 @@ def _insert_tuple(
schema_virtual_module = dj.VirtualModule(
schema_name, schema_name, connection=connection
)
getattr(schema_virtual_module, table_name).insert(tuple_to_insert)
_DJConnector._get_table_object(schema_virtual_module, table_name).insert(
tuple_to_insert
)

@staticmethod
def _record_dependency(
Expand All @@ -346,7 +350,7 @@ def _record_dependency(
virtual_module = dj.VirtualModule(
schema_name, schema_name, connection=connection
)
table = getattr(virtual_module, table_name)
table = _DJConnector._get_table_object(virtual_module, table_name)
attributes = table.heading.attributes
# Retrieve dependencies of related to retricted
dependencies = [
Expand Down Expand Up @@ -397,7 +401,9 @@ def _update_tuple(
)
with connection.transaction:
[
getattr(schema_virtual_module, table_name).update1(t)
_DJConnector._get_table_object(
schema_virtual_module, table_name
).update1(t)
for t in tuple_to_update
]

Expand Down
32 changes: 31 additions & 1 deletion tests/test_table_metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from . import SCHEMA_PREFIX, client, token, connection, schemas_simple
from . import (
SCHEMA_PREFIX,
client,
token,
connection,
schemas_simple,
schema_main,
ParentPart,
)


def test_definition(token, client, schemas_simple):
Expand All @@ -14,3 +22,25 @@ def test_definition(token, client, schemas_simple):
headers=dict(Authorization=f"Bearer {token}"),
).data
assert f"`{simple1.database}`.`#table_a`" in REST_definition.decode("utf-8")


def test_definition_part_table(token, client, ParentPart):
ScanData, ProcessScanData = ParentPart

# Test Parent
REST_value = client.get(
f"/schema/{ScanData.database}/table/{ProcessScanData.__name__}/definition",
headers=dict(Authorization=f"Bearer {token}"),
).data

assert f"{ScanData.database}.ScanData" in REST_value.decode("utf-8")

# Test Child
REST_value = client.get(
f"""/schema/{ProcessScanData.database}/table/{
ProcessScanData.__name__ + '.' +
ProcessScanData.ProcessScanDataPart.__name__}/definition""",
headers=dict(Authorization=f"Bearer {token}"),
).data

assert f"{ProcessScanData.database}.ProcessScanData" in REST_value.decode("utf-8")
Loading