Skip to content

Commit

Permalink
Merge pull request #1445 from fractal-analytics-platform/1444-forbid-…
Browse files Browse the repository at this point in the history
…extra-attributes-in-dump-models-v2

Forbid extras in `DumpV2` models and cleanup benchmarks
  • Loading branch information
tcompa committed Apr 30, 2024
2 parents b800f5a + 1e21450 commit 9e695ee
Show file tree
Hide file tree
Showing 12 changed files with 2,256 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/benchmarks.yaml
Expand Up @@ -65,7 +65,14 @@ jobs:
- name: Benchmark
run: |
cd benchmarks/
poetry run python api_bench.py ${{ github.head_ref || github.ref_name }}
poetry run python api_bench.py
- name: Print logs stderr
run: cat benchmarks/fractal-server.err

- name: Print logs stdout
run: cat benchmarks/fractal-server.out


- name: Add comment with preview
uses: mshick/add-pr-comment@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/migrations.yml
Expand Up @@ -19,7 +19,7 @@ env:
# with the SOURCE_VERSION of fractal-server.
# Here we test the script that upgrades the DB from SOURCE_VERSION to the
#current version.
SOURCE_VERSION: 2.0.0a11
SOURCE_VERSION: 2.0.1
ROOTDIR: tests/data/testing_databases

jobs:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
**Note**: Numbers like (\#123) point to closed Pull Requests on the fractal-server repository.

# 2.0.2 (Unreleased)

* API:
* Forbid extra arguments in `DumpV2` schemas (\#1445).
* Benchmarks:
* Handle some more errors in benchmark flow (\#1445).
* Tests:
* Update testing database to version 2.0.1 (\#1445).

# 2.0.1

* Database/API:
Expand Down
1 change: 1 addition & 0 deletions benchmarks/.gitignore
@@ -1,3 +1,4 @@
fractal-server.err
fractal-server.out
bench_diff.md
tmp*
6 changes: 5 additions & 1 deletion benchmarks/api_bench.py
Expand Up @@ -134,12 +134,16 @@ def get_metrics(self, user, path: str, res: Response) -> dict:
time_response = res.elapsed.total_seconds()
byte_size = len(res.content)
else:
try:
detail = res.json().get("detail")
except json.JSONDecodeError:
detail = "Cannot parse response JSON"
self.exceptions.append(
dict(
user=user,
path=path,
status=res.status_code,
detail=res.json().get("detail"),
detail=detail,
exception=res.reason_phrase,
)
)
Expand Down
5 changes: 0 additions & 5 deletions benchmarks/templates/bench_diff_template.md
Expand Up @@ -11,8 +11,3 @@ Current branch: `{{currentbranch}}`
{%endfor%}

{% endfor %}

| Path | Status | Exception |
| -- | -- | -- |
{% for exception in exceptions %}| {{exception["path"]}} | {{exception["status"]}} | {{exception["exception"] ~ " " ~ exception["detail"] ~ string}} |
{% endfor %}
4 changes: 3 additions & 1 deletion fractal_server/app/routes/api/v2/submit.py
Expand Up @@ -146,7 +146,9 @@ async def apply_workflow(
workflow_id=workflow_id,
user_email=user.email,
dataset_dump=dict(
**dataset.model_dump(exclude={"images", "timestamp_created"}),
**dataset.model_dump(
exclude={"images", "history", "timestamp_created"}
),
timestamp_created=_encode_as_utc(dataset.timestamp_created),
),
workflow_dump=dict(
Expand Down
4 changes: 2 additions & 2 deletions fractal_server/app/schemas/v2/dumps.py
Expand Up @@ -70,14 +70,14 @@ def task_v1_or_v2(cls, values):
return values


class WorkflowDumpV2(BaseModel):
class WorkflowDumpV2(BaseModel, extra=Extra.forbid):
id: int
name: str
project_id: int
timestamp_created: str


class DatasetDumpV2(BaseModel):
class DatasetDumpV2(BaseModel, extra=Extra.forbid):
id: int
name: str
project_id: int
Expand Down
11 changes: 9 additions & 2 deletions scripts/populate_db/fractal_client.py
@@ -1,5 +1,6 @@
import logging
import time
from json import JSONDecodeError

import httpx
from a2wsgi import ASGIMiddleware
Expand Down Expand Up @@ -42,8 +43,14 @@ def __init__(
"/auth/token/login/",
data=credentials,
)
print(response.json())
self.bearer_token = response.json().get("access_token")
try:
print(response.json())
self.bearer_token = response.json().get("access_token")
except JSONDecodeError as e:
logging.error("Could not parse response JSON.")
logging.error(f"Request body: {credentials}")
logging.error(f"API response: {response}")
raise e

def make_request(self, endpoint, method="GET", data=None):
headers = {"Authorization": f"Bearer {self.bearer_token}"}
Expand Down

0 comments on commit 9e695ee

Please sign in to comment.