Skip to content

Commit

Permalink
Merge pull request #151 from A-Baji/datetime-bug
Browse files Browse the repository at this point in the history
fix for datetime FPK in form component
  • Loading branch information
jverswijver authored Jan 31, 2023
2 parents d3808ae + a850dbf commit 91b8713
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 28 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

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.7.3] - 2023-01-31

### Bugfix

- Fix datetime FPK format for forms (#152) [#151](https://github.com/datajoint/pharus/pull/151)

## [0.7.2] - 2023-01-13

### Bugfix

- Re-add `antd-table` to regex match for dynamic api gen [#150] (https://github.com/datajoint/pharus/pull/150)
- Re-add `antd-table` to regex match for dynamic api gen [#150](https://github.com/datajoint/pharus/pull/150)

## [0.7.1] - 2023-01-10

### Bugfix

- Keyword arguments fixed, host -> databaseAddress and user -> username PR [#149] (https://github.com/datajoint/pharus/pull/149)
- Keyword arguments fixed, host -> databaseAddress and user -> username PR [#149](https://github.com/datajoint/pharus/pull/149)

## [0.7.0] - 2023-01-05

Expand All @@ -35,7 +41,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and

### Added

- Added attribute default value to the form component field route response
- Added attribute default value to the form component field route response [#147](https://github.com/datajoint/pharus/pull/147)

## [0.6.2] - 2022-11-10

Expand Down Expand Up @@ -255,6 +261,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.7.3]: https://github.com/datajoint/pharus/compare/0.7.2...0.7.3
[0.7.2]: https://github.com/datajoint/pharus/compare/0.7.1...0.7.2
[0.7.1]: https://github.com/datajoint/pharus/compare/0.7.0...0.7.1
[0.7.0]: https://github.com/datajoint/pharus/compare/0.6.4...0.7.0
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ To start the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml up -d
PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml up -d
To stop the API server, use the command:

.. code-block:: bash
PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml down
PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml down
References
----------
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml up -d
# PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml up -d
#
# Intended for production deployment.
# Note: You must run both commands above for minimal outage
Expand Down
9 changes: 7 additions & 2 deletions pharus/component_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def fields_route(self):
source_fields = {
**{
(p_name := f"{p.database}.{dj.utils.to_camel_case(p.table_name)}"): {
"values": p.fetch("KEY"),
"values": [NumpyEncoder.dumps(row) for row in p.fetch("KEY")],
"type": "table",
"name": p_name,
}
Expand Down Expand Up @@ -247,7 +247,12 @@ def fields_route(self):
**(
{
"values": [
{self.input_lookup.get(k, k): v for k, v in r.items()}
json.dumps(
{
self.input_lookup.get(k, k): v
for k, v in json.loads(r).items()
}
)
for r in field["values"]
]
}
Expand Down
2 changes: 1 addition & 1 deletion pharus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def api_version() -> str:
Content-Type: application/json
{
"version": "0.7.2"
"version": "0.7.3"
}
:statuscode 200: No error.
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.7.2"
__version__ = "0.7.3"
19 changes: 19 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ class TableW(dj.Lookup):
w_int = 123 : int
"""

@group4_simple
class TableV(dj.Lookup):
definition = """
datetime: datetime
v_int: int
"""
contents = [
("2000-01-02 01:02:03", 0),
("2023-12-1 23:12:01", 1),
]

@group4_simple
class TableU(dj.Lookup):
definition = """
-> TableV
---
u_int = 1 : int
"""

@group1_simple
class PlotlyTable(dj.Lookup):
definition = """
Expand Down
9 changes: 9 additions & 0 deletions tests/init/test_dynamic_api_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ SciViz: # top level tab
- test_group3_simple.TableY
- test_group4_simple.DiffTableY
- test_group4_simple.TableW
insert9:
route: /insert9
x: 1
y: 2
height: 1
width: 1
type: form
tables:
- test_group4_simple.TableU
component1:
route: /query1
row_span: 0
Expand Down
63 changes: 46 additions & 17 deletions tests/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def test_form_response(token, client, connection, schemas_simple):
"type": "attribute",
"default": None,
},
{"name": "Table A", "type": "table", "values": [{"A Id": 0}, {"A Id": 1}]},
{
"name": "Table A",
"type": "table",
"values": ['{"A Id": 0}', '{"A Id": 1}'],
},
{"datatype": "int", "name": "C Id", "type": "attribute", "default": None},
{
"datatype": "varchar(30)",
Expand All @@ -101,7 +105,11 @@ def test_form_response_no_table_map(token, client, connection, schemas_simple):
"type": "attribute",
"default": None,
},
{"name": "Table A", "type": "table", "values": [{"a_id": 0}, {"a_id": 1}]},
{
"name": "Table A",
"type": "table",
"values": ['{"a_id": 0}', '{"a_id": 1}'],
},
{"datatype": "int", "name": "C Id", "type": "attribute", "default": None},
{
"datatype": "varchar(30)",
Expand All @@ -124,7 +132,7 @@ def test_form_response_no_map(token, client, connection, schemas_simple):
{
"name": "test_group1_simple.TableA",
"type": "table",
"values": [{"a_id": 0}, {"a_id": 1}],
"values": ['{"a_id": 0}', '{"a_id": 1}'],
},
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
{
Expand Down Expand Up @@ -157,15 +165,15 @@ def test_form_response_no_map_shared_FK_hierarchy(
{
"name": "test_group1_simple.TableA",
"type": "table",
"values": [{"a_id": 0}, {"a_id": 1}],
"values": ['{"a_id": 0}', '{"a_id": 1}'],
},
{
"name": "test_group1_simple.TableB",
"type": "table",
"values": [
{"a_id": 0, "b_id": 10},
{"a_id": 0, "b_id": 11},
{"a_id": 1, "b_id": 21},
'{"a_id": 0, "b_id": 10}',
'{"a_id": 0, "b_id": 11}',
'{"a_id": 1, "b_id": 21}',
],
},
{"datatype": "int", "name": "bs_id", "type": "attribute", "default": None},
Expand Down Expand Up @@ -197,7 +205,7 @@ def test_form_response_no_map_shared_FK(token, client, connection, schemas_simpl
{
"name": "test_group1_simple.TableA",
"type": "table",
"values": [{"a_id": 0}, {"a_id": 1}],
"values": ['{"a_id": 0}', '{"a_id": 1}'],
},
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
{
Expand Down Expand Up @@ -228,12 +236,12 @@ def test_form_response_no_map_diff_FK(token, client, connection, schemas_simple)
{
"name": "test_group3_simple.TableZ",
"type": "table",
"values": [{"z_id": 0}, {"z_id": 1}],
"values": ['{"z_id": 0}', '{"z_id": 1}'],
},
{
"name": "test_group4_simple.DiffTableZ",
"type": "table",
"values": [{"zs_id": 0}, {"zs_id": 1}],
"values": ['{"zs_id": 0}', '{"zs_id": 1}'],
},
{"datatype": "int", "name": "y_id", "type": "attribute", "default": None},
{
Expand Down Expand Up @@ -265,8 +273,8 @@ def test_form_response_no_map_multi_FPK(token, client, connection, schemas_simpl
"name": "test_group3_simple.TableX",
"type": "table",
"values": [
{"x_id": 0, "x_int": 10, "x_name": "Carlos"},
{"x_id": 1, "x_int": 20, "x_name": "Oscar"},
'{"x_id": 0, "x_name": "Carlos", "x_int": 10}',
'{"x_id": 1, "x_name": "Oscar", "x_int": 20}',
],
},
{"datatype": "int", "name": "w_id", "type": "attribute", "default": None},
Expand All @@ -286,25 +294,25 @@ def test_form_response_no_map_many_tables(token, client, connection, schemas_sim
{
"name": "test_group1_simple.TableA",
"type": "table",
"values": [{"a_id": 0}, {"a_id": 1}],
"values": ['{"a_id": 0}', '{"a_id": 1}'],
},
{
"name": "test_group3_simple.TableX",
"type": "table",
"values": [
{"x_id": 0, "x_int": 10, "x_name": "Carlos"},
{"x_id": 1, "x_int": 20, "x_name": "Oscar"},
'{"x_id": 0, "x_name": "Carlos", "x_int": 10}',
'{"x_id": 1, "x_name": "Oscar", "x_int": 20}',
],
},
{
"name": "test_group3_simple.TableZ",
"type": "table",
"values": [{"z_id": 0}, {"z_id": 1}],
"values": ['{"z_id": 0}', '{"z_id": 1}'],
},
{
"name": "test_group4_simple.DiffTableZ",
"type": "table",
"values": [{"zs_id": 0}, {"zs_id": 1}],
"values": ['{"zs_id": 0}', '{"zs_id": 1}'],
},
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
{
Expand Down Expand Up @@ -345,3 +353,24 @@ def test_form_response_no_map_many_tables(token, client, connection, schemas_sim
{"datatype": "int", "name": "w_int", "type": "attribute", "default": "123"},
]
}


def test_form_datetime_FPK(token, client, connection, schemas_simple):
REST_response = client.get(
"/insert9/fields",
headers=dict(Authorization=f"Bearer {token}"),
)
assert REST_response.status_code == 200, f"Error: {REST_response.data}"
assert REST_response.get_json() == {
"fields": [
{
"name": "test_group4_simple.TableV",
"type": "table",
"values": [
'{"datetime": "2000-01-02T01:02:03", "v_int": 0}',
'{"datetime": "2023-12-01T23:12:01", "v_int": 1}',
],
},
{"datatype": "int", "default": "1", "name": "u_int", "type": "attribute"},
]
}

0 comments on commit 91b8713

Please sign in to comment.