|
22 | 22 | from datajoint.errors import IntegrityError |
23 | 23 | from datajoint.table import foreign_key_error_regexp |
24 | 24 | from datajoint.utils import to_camel_case |
| 25 | +import traceback |
| 26 | +import time |
25 | 27 |
|
26 | 28 | app = Flask(__name__) |
27 | 29 | # Check if PRIVATE_KEY and PUBIC_KEY is set, if not generate them. |
@@ -124,7 +126,7 @@ def api_version() -> str: |
124 | 126 | Content-Type: application/json |
125 | 127 |
|
126 | 128 | { |
127 | | - "version": "0.6.0" |
| 129 | + "version": "0.6.1" |
128 | 130 | } |
129 | 131 |
|
130 | 132 | :statuscode 200: No error. |
@@ -233,6 +235,7 @@ def login() -> dict: |
233 | 235 | auth_info = dict( |
234 | 236 | jwt=result.json()["access_token"], id=result.json()["id_token"] |
235 | 237 | ) |
| 238 | + time.sleep(1) |
236 | 239 | connect_creds = { |
237 | 240 | "databaseAddress": request.args["database_host"], |
238 | 241 | "username": jwt.decode( |
@@ -281,7 +284,7 @@ def login() -> dict: |
281 | 284 | raise e |
282 | 285 | return dict(**auth_info) |
283 | 286 | except Exception as e: |
284 | | - return str(e), 500 |
| 287 | + return traceback.format_exc(), 500 |
285 | 288 |
|
286 | 289 |
|
287 | 290 | @app.route(f"{environ.get('PHARUS_PREFIX', '')}/schema", methods=["GET"]) |
@@ -343,7 +346,7 @@ def schema(connection: dj.Connection) -> dict: |
343 | 346 | schemas_name = _DJConnector._list_schemas(connection) |
344 | 347 | return dict(schemaNames=schemas_name) |
345 | 348 | except Exception as e: |
346 | | - return str(e), 500 |
| 349 | + return traceback.format_exc(), 500 |
347 | 350 |
|
348 | 351 |
|
349 | 352 | @app.route( |
@@ -420,7 +423,7 @@ def table( |
420 | 423 | tables_dict_list = _DJConnector._list_tables(connection, schema_name) |
421 | 424 | return dict(tableTypes=tables_dict_list) |
422 | 425 | except Exception as e: |
423 | | - return str(e), 500 |
| 426 | + return traceback.format_exc(), 500 |
424 | 427 |
|
425 | 428 |
|
426 | 429 | @app.route( |
@@ -742,23 +745,23 @@ def record( |
742 | 745 | recordHeader=record_header, records=table_tuples, totalCount=total_count |
743 | 746 | ) |
744 | 747 | except Exception as e: |
745 | | - return str(e), 500 |
| 748 | + return traceback.format_exc(), 500 |
746 | 749 | elif request.method == "POST": |
747 | 750 | try: |
748 | 751 | _DJConnector._insert_tuple( |
749 | 752 | connection, schema_name, table_name, request.json["records"] |
750 | 753 | ) |
751 | 754 | return "Insert Successful" |
752 | 755 | except Exception as e: |
753 | | - return str(e), 500 |
| 756 | + return traceback.format_exc(), 500 |
754 | 757 | elif request.method == "PATCH": |
755 | 758 | try: |
756 | 759 | _DJConnector._update_tuple( |
757 | 760 | connection, schema_name, table_name, request.json["records"] |
758 | 761 | ) |
759 | 762 | return "Update Successful" |
760 | 763 | except Exception as e: |
761 | | - return str(e), 500 |
| 764 | + return traceback.format_exc(), 500 |
762 | 765 | elif request.method == "DELETE": |
763 | 766 | try: |
764 | 767 | _DJConnector._delete_records( |
@@ -789,7 +792,7 @@ def record( |
789 | 792 | 409, |
790 | 793 | ) |
791 | 794 | except Exception as e: |
792 | | - return str(e), 500 |
| 795 | + return traceback.format_exc(), 500 |
793 | 796 |
|
794 | 797 |
|
795 | 798 | @app.route( |
@@ -872,7 +875,7 @@ def definition( |
872 | 875 | ) |
873 | 876 | return table_definition |
874 | 877 | except Exception as e: |
875 | | - return str(e), 500 |
| 878 | + return traceback.format_exc(), 500 |
876 | 879 |
|
877 | 880 |
|
878 | 881 | @app.route( |
@@ -1051,7 +1054,7 @@ def attribute( |
1051 | 1054 | attributes=attributes_meta["attributes"], |
1052 | 1055 | ) |
1053 | 1056 | except Exception as e: |
1054 | | - return str(e), 500 |
| 1057 | + return traceback.format_exc(), 500 |
1055 | 1058 |
|
1056 | 1059 |
|
1057 | 1060 | @app.route( |
@@ -1158,14 +1161,14 @@ def dependency( |
1158 | 1161 | ) |
1159 | 1162 | return dict(dependencies=dependencies) |
1160 | 1163 | except Exception as e: |
1161 | | - return str(e), 500 |
| 1164 | + return traceback.format_exc(), 500 |
1162 | 1165 |
|
1163 | 1166 |
|
1164 | 1167 | def run(): |
1165 | 1168 | """ |
1166 | 1169 | Starts API server. |
1167 | 1170 | """ |
1168 | | - app.run(host="0.0.0.0", port=environ.get("PHARUS_PORT", 5000), threaded=True) |
| 1171 | + app.run(host="0.0.0.0", port=environ.get("PHARUS_PORT", 5000), threaded=False) |
1169 | 1172 |
|
1170 | 1173 |
|
1171 | 1174 | if __name__ == "__main__": |
|
0 commit comments