|
9 | 9 | from pathlib import Path |
10 | 10 | from typing import Awaitable, Callable, Generic, Optional, TypeVar |
11 | 11 |
|
12 | | -import attrs |
13 | 12 | from generics import get_filled_type |
14 | | -from pydantic import BaseModel, TypeAdapter, ValidationError # pylint:disable=no-name-in-module |
| 13 | +from pydantic import BaseModel, TypeAdapter, ConfigDict, ValidationError # pylint:disable=no-name-in-module |
15 | 14 |
|
16 | 15 | _TargetEntity = TypeVar("_TargetEntity") |
17 | 16 |
|
18 | 17 |
|
19 | | -@attrs.define(auto_attribs=True, kw_only=True) |
20 | | -class EntityLoadingResult: # pylint:disable=too-few-public-methods |
| 18 | +class EntityLoadingResult(BaseModel): # pylint:disable=too-few-public-methods |
21 | 19 | """ |
22 | 20 | Information gathered while loading a _TargetEntity into the target system. |
23 | 21 | """ |
24 | 22 |
|
25 | | - id_in_target_system: Optional[str] = attrs.field( |
26 | | - validator=attrs.validators.optional(attrs.validators.instance_of(str)), default=None |
27 | | - ) |
| 23 | + model_config = ConfigDict(arbitrary_types_allowed=True) |
| 24 | + |
| 25 | + id_in_target_system: Optional[str] = None |
28 | 26 | """ |
29 | 27 | the optional ID of the entity in the target system (e.g. if a new (GU)ID is generated upon loading) |
30 | 28 | """ |
31 | | - polling_task: Optional[Awaitable] = attrs.field(default=None) |
| 29 | + polling_task: Optional[Awaitable] = None |
32 | 30 | """ |
33 | 31 | If this task is awaited it means, that the target system is done with processing the request. |
34 | 32 | A possible use case is that the target system responds with something like an event ID which can be used to poll |
35 | 33 | an endpoint until it returns the expected result. |
36 | 34 | """ |
37 | 35 |
|
38 | 36 |
|
39 | | -@attrs.define(auto_attribs=True, kw_only=True) |
40 | | -class LoadingSummary(ABC, Generic[_TargetEntity]): # pylint:disable=too-few-public-methods |
| 37 | +class LoadingSummary(BaseModel, ABC, Generic[_TargetEntity]): # pylint:disable=too-few-public-methods |
41 | 38 | """ |
42 | 39 | Each instance of _TargetEntity that is loaded to the target system results in a LoadingSummary. |
43 | 40 | It is a summary that reports to calling code. |
44 | 41 | """ |
45 | 42 |
|
46 | | - was_loaded_successfully: bool = attrs.field(validator=attrs.validators.instance_of(bool)) |
| 43 | + model_config = ConfigDict(arbitrary_types_allowed=True) |
| 44 | + |
| 45 | + was_loaded_successfully: bool |
47 | 46 | """ |
48 | 47 | true iff the instance has been loaded successfully |
49 | 48 | """ |
50 | | - loaded_at: Optional[datetime] = attrs.field( |
51 | | - validator=attrs.validators.optional(attrs.validators.instance_of(datetime)), default=None |
52 | | - ) |
| 49 | + loaded_at: Optional[datetime] = None |
53 | 50 | """ |
54 | 51 | point in time at which the loading (without verification) has completed; if not None |
55 | 52 | """ |
56 | | - verified_at: Optional[datetime] = attrs.field( |
57 | | - validator=attrs.validators.optional(attrs.validators.instance_of(datetime)), default=None |
58 | | - ) |
| 53 | + verified_at: Optional[datetime] = None |
59 | 54 | """ |
60 | 55 | point in time at which the loading of this entity has been verified (or None if not) |
61 | 56 | """ |
62 | | - id_in_target_system: Optional[str] = attrs.field( |
63 | | - validator=attrs.validators.optional(attrs.validators.instance_of(str)), default=None |
64 | | - ) |
| 57 | + id_in_target_system: Optional[str] = None |
65 | 58 | """ |
66 | 59 | the optional ID of the entity in the target system (e.g. if a new (GU)ID is generated upon loading) |
67 | 60 | """ |
68 | | - loading_error: Optional[Exception] = attrs.field(default=None) |
| 61 | + loading_error: Optional[Exception] = None |
69 | 62 |
|
70 | 63 |
|
71 | 64 | class EntityLoader(ABC, Generic[_TargetEntity]): # pylint:disable=too-few-public-methods |
|
0 commit comments