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

Add error handling for 404s #168

Merged
merged 2 commits into from
Oct 2, 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
7 changes: 7 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.9] - 2023-10-02

### Added

- Throw new errors for invalid schemas and tables [#168](https://github.com/datajoint/pharus/pull/168)

## [0.8.8] - 2023-09-20

### Changed
Expand Down Expand Up @@ -321,6 +327,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
- Check dependency utility to determine child table references.

[0.8.9]: https://github.com/datajoint/pharus/compare/0.8.8...0.8.9
[0.8.8]: https://github.com/datajoint/pharus/compare/0.8.7...0.8.8
[0.8.7]: https://github.com/datajoint/pharus/compare/0.8.6...0.8.7
[0.8.6]: https://github.com/datajoint/pharus/compare/0.8.5...0.8.6
Expand Down
12 changes: 12 additions & 0 deletions pharus/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ class InvalidRestriction(Exception):
"""Exception raised when restrictions result in no records when expected at least one."""

pass


class SchemaNotFound(Exception):
"""Exception raised when a given schema is not found to exist"""

pass


class TableNotFound(Exception):
"""Exception raised when a given table is not found to exist"""

pass
32 changes: 22 additions & 10 deletions pharus/interface.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""Library for interfaces into DataJoint pipelines."""
import datajoint as dj
from datajoint import DataJointError
from datajoint.utils import to_camel_case
from datajoint.user_tables import UserTable
from datajoint import VirtualModule
import datetime
import numpy as np
import re
from .error import InvalidRestriction, UnsupportedTableType
from .error import (
InvalidRestriction,
UnsupportedTableType,
SchemaNotFound,
TableNotFound,
)

DAY = 24 * 60 * 60
DEFAULT_FETCH_LIMIT = 1000 # Stop gap measure to deal with super large tables
Expand Down Expand Up @@ -60,9 +66,11 @@ def _list_tables(
"""

# Get list of tables names
tables_name = dj.Schema(
schema_name, create_schema=False, connection=connection
).list_tables()
try:
schema = dj.Schema(schema_name, create_schema=False, connection=connection)
except DataJointError:
raise SchemaNotFound("Schema does not exist")
tables_name = schema.list_tables()
# Dict to store list of table name for each type
tables_dict_list = dict(manual=[], lookup=[], computed=[], imported=[], part=[])
# Loop through each table name to figure out what type it is and add them to
Expand Down Expand Up @@ -452,12 +460,16 @@ def _get_table_object(

# Split the table name by '.' for dealing with part tables
table_name_parts = table_name.split(".")
if len(table_name_parts) == 2:
return getattr(
getattr(schema_virtual_module, table_name_parts[0]), table_name_parts[1]
)
else:
return getattr(schema_virtual_module, table_name_parts[0])
try:
if len(table_name_parts) == 2:
return getattr(
getattr(schema_virtual_module, table_name_parts[0]),
table_name_parts[1],
)
else:
return getattr(schema_virtual_module, table_name_parts[0])
except AttributeError:
raise TableNotFound("Table does not exist")

@staticmethod
def _filter_to_restriction(attribute_filter: dict, attribute_type: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pharus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def api_version() -> str:
Content-Type: application/json

{
"version": "0.8.8"
"version": "0.8.9"
}
```

Expand Down
2 changes: 1 addition & 1 deletion pharus/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Package metadata."""
__version__ = "0.8.8"
__version__ = "0.8.9"
Loading