Skip to content

Commit 91b8713

Browse files
authored
Merge pull request #151 from A-Baji/datetime-bug
fix for datetime FPK in form component
2 parents d3808ae + a850dbf commit 91b8713

File tree

9 files changed

+97
-28
lines changed

9 files changed

+97
-28
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

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

5+
## [0.7.3] - 2023-01-31
6+
7+
### Bugfix
8+
9+
- Fix datetime FPK format for forms (#152) [#151](https://github.com/datajoint/pharus/pull/151)
10+
511
## [0.7.2] - 2023-01-13
612

713
### Bugfix
814

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

1117
## [0.7.1] - 2023-01-10
1218

1319
### Bugfix
1420

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

1723
## [0.7.0] - 2023-01-05
1824

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

3642
### Added
3743

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

4046
## [0.6.2] - 2022-11-10
4147

@@ -255,6 +261,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
255261
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
256262
- Check dependency utility to determine child table references.
257263

264+
[0.7.3]: https://github.com/datajoint/pharus/compare/0.7.2...0.7.3
258265
[0.7.2]: https://github.com/datajoint/pharus/compare/0.7.1...0.7.2
259266
[0.7.1]: https://github.com/datajoint/pharus/compare/0.7.0...0.7.1
260267
[0.7.0]: https://github.com/datajoint/pharus/compare/0.6.4...0.7.0

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ To start the API server, use the command:
2929

3030
.. code-block:: bash
3131
32-
PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml up -d
32+
PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml up -d
3333
3434
To stop the API server, use the command:
3535

3636
.. code-block:: bash
3737
38-
PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml down
38+
PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml down
3939
4040
References
4141
----------

docker-compose-deploy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml pull
2-
# PHARUS_VERSION=0.7.2 docker-compose -f docker-compose-deploy.yaml up -d
1+
# PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml pull
2+
# PHARUS_VERSION=0.7.3 docker-compose -f docker-compose-deploy.yaml up -d
33
#
44
# Intended for production deployment.
55
# Note: You must run both commands above for minimal outage

pharus/component_interface.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def fields_route(self):
214214
source_fields = {
215215
**{
216216
(p_name := f"{p.database}.{dj.utils.to_camel_case(p.table_name)}"): {
217-
"values": p.fetch("KEY"),
217+
"values": [NumpyEncoder.dumps(row) for row in p.fetch("KEY")],
218218
"type": "table",
219219
"name": p_name,
220220
}
@@ -247,7 +247,12 @@ def fields_route(self):
247247
**(
248248
{
249249
"values": [
250-
{self.input_lookup.get(k, k): v for k, v in r.items()}
250+
json.dumps(
251+
{
252+
self.input_lookup.get(k, k): v
253+
for k, v in json.loads(r).items()
254+
}
255+
)
251256
for r in field["values"]
252257
]
253258
}

pharus/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def api_version() -> str:
126126
Content-Type: application/json
127127
128128
{
129-
"version": "0.7.2"
129+
"version": "0.7.3"
130130
}
131131
132132
:statuscode 200: No error.

pharus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Package metadata."""
2-
__version__ = "0.7.2"
2+
__version__ = "0.7.3"

tests/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,25 @@ class TableW(dj.Lookup):
276276
w_int = 123 : int
277277
"""
278278

279+
@group4_simple
280+
class TableV(dj.Lookup):
281+
definition = """
282+
datetime: datetime
283+
v_int: int
284+
"""
285+
contents = [
286+
("2000-01-02 01:02:03", 0),
287+
("2023-12-1 23:12:01", 1),
288+
]
289+
290+
@group4_simple
291+
class TableU(dj.Lookup):
292+
definition = """
293+
-> TableV
294+
---
295+
u_int = 1 : int
296+
"""
297+
279298
@group1_simple
280299
class PlotlyTable(dj.Lookup):
281300
definition = """

tests/init/test_dynamic_api_spec.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ SciViz: # top level tab
132132
- test_group3_simple.TableY
133133
- test_group4_simple.DiffTableY
134134
- test_group4_simple.TableW
135+
insert9:
136+
route: /insert9
137+
x: 1
138+
y: 2
139+
height: 1
140+
width: 1
141+
type: form
142+
tables:
143+
- test_group4_simple.TableU
135144
component1:
136145
route: /query1
137146
row_span: 0

tests/test_form.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def test_form_response(token, client, connection, schemas_simple):
7474
"type": "attribute",
7575
"default": None,
7676
},
77-
{"name": "Table A", "type": "table", "values": [{"A Id": 0}, {"A Id": 1}]},
77+
{
78+
"name": "Table A",
79+
"type": "table",
80+
"values": ['{"A Id": 0}', '{"A Id": 1}'],
81+
},
7882
{"datatype": "int", "name": "C Id", "type": "attribute", "default": None},
7983
{
8084
"datatype": "varchar(30)",
@@ -101,7 +105,11 @@ def test_form_response_no_table_map(token, client, connection, schemas_simple):
101105
"type": "attribute",
102106
"default": None,
103107
},
104-
{"name": "Table A", "type": "table", "values": [{"a_id": 0}, {"a_id": 1}]},
108+
{
109+
"name": "Table A",
110+
"type": "table",
111+
"values": ['{"a_id": 0}', '{"a_id": 1}'],
112+
},
105113
{"datatype": "int", "name": "C Id", "type": "attribute", "default": None},
106114
{
107115
"datatype": "varchar(30)",
@@ -124,7 +132,7 @@ def test_form_response_no_map(token, client, connection, schemas_simple):
124132
{
125133
"name": "test_group1_simple.TableA",
126134
"type": "table",
127-
"values": [{"a_id": 0}, {"a_id": 1}],
135+
"values": ['{"a_id": 0}', '{"a_id": 1}'],
128136
},
129137
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
130138
{
@@ -157,15 +165,15 @@ def test_form_response_no_map_shared_FK_hierarchy(
157165
{
158166
"name": "test_group1_simple.TableA",
159167
"type": "table",
160-
"values": [{"a_id": 0}, {"a_id": 1}],
168+
"values": ['{"a_id": 0}', '{"a_id": 1}'],
161169
},
162170
{
163171
"name": "test_group1_simple.TableB",
164172
"type": "table",
165173
"values": [
166-
{"a_id": 0, "b_id": 10},
167-
{"a_id": 0, "b_id": 11},
168-
{"a_id": 1, "b_id": 21},
174+
'{"a_id": 0, "b_id": 10}',
175+
'{"a_id": 0, "b_id": 11}',
176+
'{"a_id": 1, "b_id": 21}',
169177
],
170178
},
171179
{"datatype": "int", "name": "bs_id", "type": "attribute", "default": None},
@@ -197,7 +205,7 @@ def test_form_response_no_map_shared_FK(token, client, connection, schemas_simpl
197205
{
198206
"name": "test_group1_simple.TableA",
199207
"type": "table",
200-
"values": [{"a_id": 0}, {"a_id": 1}],
208+
"values": ['{"a_id": 0}', '{"a_id": 1}'],
201209
},
202210
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
203211
{
@@ -228,12 +236,12 @@ def test_form_response_no_map_diff_FK(token, client, connection, schemas_simple)
228236
{
229237
"name": "test_group3_simple.TableZ",
230238
"type": "table",
231-
"values": [{"z_id": 0}, {"z_id": 1}],
239+
"values": ['{"z_id": 0}', '{"z_id": 1}'],
232240
},
233241
{
234242
"name": "test_group4_simple.DiffTableZ",
235243
"type": "table",
236-
"values": [{"zs_id": 0}, {"zs_id": 1}],
244+
"values": ['{"zs_id": 0}', '{"zs_id": 1}'],
237245
},
238246
{"datatype": "int", "name": "y_id", "type": "attribute", "default": None},
239247
{
@@ -265,8 +273,8 @@ def test_form_response_no_map_multi_FPK(token, client, connection, schemas_simpl
265273
"name": "test_group3_simple.TableX",
266274
"type": "table",
267275
"values": [
268-
{"x_id": 0, "x_int": 10, "x_name": "Carlos"},
269-
{"x_id": 1, "x_int": 20, "x_name": "Oscar"},
276+
'{"x_id": 0, "x_name": "Carlos", "x_int": 10}',
277+
'{"x_id": 1, "x_name": "Oscar", "x_int": 20}',
270278
],
271279
},
272280
{"datatype": "int", "name": "w_id", "type": "attribute", "default": None},
@@ -286,25 +294,25 @@ def test_form_response_no_map_many_tables(token, client, connection, schemas_sim
286294
{
287295
"name": "test_group1_simple.TableA",
288296
"type": "table",
289-
"values": [{"a_id": 0}, {"a_id": 1}],
297+
"values": ['{"a_id": 0}', '{"a_id": 1}'],
290298
},
291299
{
292300
"name": "test_group3_simple.TableX",
293301
"type": "table",
294302
"values": [
295-
{"x_id": 0, "x_int": 10, "x_name": "Carlos"},
296-
{"x_id": 1, "x_int": 20, "x_name": "Oscar"},
303+
'{"x_id": 0, "x_name": "Carlos", "x_int": 10}',
304+
'{"x_id": 1, "x_name": "Oscar", "x_int": 20}',
297305
],
298306
},
299307
{
300308
"name": "test_group3_simple.TableZ",
301309
"type": "table",
302-
"values": [{"z_id": 0}, {"z_id": 1}],
310+
"values": ['{"z_id": 0}', '{"z_id": 1}'],
303311
},
304312
{
305313
"name": "test_group4_simple.DiffTableZ",
306314
"type": "table",
307-
"values": [{"zs_id": 0}, {"zs_id": 1}],
315+
"values": ['{"zs_id": 0}', '{"zs_id": 1}'],
308316
},
309317
{"datatype": "int", "name": "b_id", "type": "attribute", "default": None},
310318
{
@@ -345,3 +353,24 @@ def test_form_response_no_map_many_tables(token, client, connection, schemas_sim
345353
{"datatype": "int", "name": "w_int", "type": "attribute", "default": "123"},
346354
]
347355
}
356+
357+
358+
def test_form_datetime_FPK(token, client, connection, schemas_simple):
359+
REST_response = client.get(
360+
"/insert9/fields",
361+
headers=dict(Authorization=f"Bearer {token}"),
362+
)
363+
assert REST_response.status_code == 200, f"Error: {REST_response.data}"
364+
assert REST_response.get_json() == {
365+
"fields": [
366+
{
367+
"name": "test_group4_simple.TableV",
368+
"type": "table",
369+
"values": [
370+
'{"datetime": "2000-01-02T01:02:03", "v_int": 0}',
371+
'{"datetime": "2023-12-01T23:12:01", "v_int": 1}',
372+
],
373+
},
374+
{"datatype": "int", "default": "1", "name": "u_int", "type": "attribute"},
375+
]
376+
}

0 commit comments

Comments
 (0)