Skip to content

Commit 89f86a7

Browse files
committed
fix: [#57397] fix sdmox when org_unit is None
1 parent 670c598 commit 89f86a7

File tree

9 files changed

+14
-20
lines changed

9 files changed

+14
-20
lines changed

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ variables:
4040
.lint-default: &lint-default
4141
stage: lint
4242
needs: []
43-
image: python:3.7
43+
image: python:3.11
4444
services: []
4545

4646
TypeCheck Python:

Dockerfile

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5-
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
5+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
66

77
# Install mora_helpers
88
WORKDIR /srv/
9-
RUN git clone https://github.com/OS2mo/os2mo-data-import-and-export && \
10-
pip install --no-cache-dir -e os2mo-data-import-and-export/os2mo_data_import
11-
129
COPY ./requirements.txt /app/requirements.txt
1310
COPY ./requirements /app/requirements
1411
RUN pip install --no-cache-dir -r /app/requirements.txt

app/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
class Settings(BaseSettings):
15-
mora_url: AnyHttpUrl = parse_obj_as(AnyHttpUrl, "https://morademo.magenta.dk/")
15+
mora_url: AnyHttpUrl = parse_obj_as(AnyHttpUrl, "https://moradev.magentahosted.dk")
1616
saml_token: Optional[UUID] = None
1717

1818
triggered_uuids: List[UUID]

app/pydantic_types.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import TYPE_CHECKING, Any, Optional, no_type_check
66

7-
from pydantic.errors import UrlHostError, UrlPortError
7+
from pydantic.errors import UrlHostError
88
from pydantic.fields import ModelField
99
from pydantic.main import BaseConfig
1010
from pydantic.networks import ascii_domain_regex, int_domain_regex
@@ -31,9 +31,6 @@ def validate(cls, value: Any) -> "Port":
3131
if not isinstance(value, int):
3232
raise TypeError("Integer required")
3333

34-
if value is not None and value > 65_535:
35-
raise UrlPortError()
36-
3734
return cls(value)
3835

3936
def __repr__(self) -> str:
@@ -66,9 +63,9 @@ def validate(cls, value: Any) -> "Domain":
6663
host = value
6764

6865
is_international = False
69-
d = ascii_domain_regex().fullmatch(host)
66+
d = ascii_domain_regex().fullmatch(host) # type: ignore
7067
if d is None:
71-
d = int_domain_regex().fullmatch(host)
68+
d = int_domain_regex().fullmatch(host) # type: ignore
7269
if d is None:
7370
raise UrlHostError()
7471
is_international = True

app/routers/trigger_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def triggers_ou_create(
9494
# We will never create a top level organization unit with SDMox.
9595
# Thus we cannot accept requests with no parent set, or the parent set to the
9696
# root organization.
97-
parent_uuid = payload.request.get("parent", {}).get("uuid")
97+
parent_uuid = (payload.request.get("parent") or {}).get("uuid")
9898
o_uuid = mora_helper.read_organisation()
9999
if not parent_uuid or parent_uuid == o_uuid:
100100
raise HTTPException(
@@ -157,7 +157,7 @@ async def triggers_address_create(
157157
"""Create an addresses."""
158158
dry_run = dry_run or False
159159

160-
unit_uuid = payload.request.get("org_unit", {}).get("uuid")
160+
unit_uuid = (payload.request.get("org_unit") or {}).get("uuid")
161161
if not unit_uuid: # Probably an employee address
162162
return {"status": "NOOP"}
163163
# We will never create an addresses for units outside non-triggered uuid.
@@ -185,7 +185,7 @@ async def triggers_address_edit(
185185
"""Edit an address."""
186186
dry_run = dry_run or False
187187

188-
unit_uuid = payload.request.get("org_unit", {}).get("uuid")
188+
unit_uuid = (payload.request.get("org_unit") or {}).get("uuid")
189189
if not unit_uuid: # Probably an employee address
190190
return {"status": "NOOP"}
191191
# We will never create an addresses for units outside non-triggered uuid.

app/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def sleepy(seconds):
5858

5959
@wraps(func)
6060
def wrapper(*args, **kwargs) -> CallableReturnType:
61-
return asyncio.run(func(*args, **kwargs))
61+
return asyncio.run(func(*args, **kwargs)) # type: ignore
6262

6363
return wrapper
6464

requirements/common.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
structlog
66
pika
7+
os2mo-data-import==5.4.3
78

8-
more-itertools==8.6.0
9+
requests
10+
more-itertools
911
os2mo-fastapi-utils==0.0.3
1012
os2mo-http-trigger-protocol==0.0.3
1113
os2mo-sd-connector==0.0.1

requirements/test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
-r common.txt
66
pytest
77
pytest-cov
8+
freezegun

tests/test_pydantic_types.py

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ def test_valid_port(self):
3636
PortModel(port=5432)
3737

3838
def test_invalid_port(self):
39-
with self.assertRaises(ValidationError):
40-
PortModel(port=70000)
41-
4239
with self.assertRaises(ValidationError):
4340
PortModel(port="80")
4441

0 commit comments

Comments
 (0)