generated from Hochfrequenz/python_template_repository
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add JSON column w/ Kommunikationsrichtungen to Anwendungsfall table (fix cyclic import problem with Kommunikationseinrichtung model) #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3fca0bd
feat: add JSON column to Anwendungsfall table w/ Kommunikationsrichtu…
bdaae41
fix flaky test
febdfa0
fix default
0d4a6e8
Merge branch 'main' into use-parsed-kv
hf-kklein 144de0c
Merge branch 'main' into use-parsed-kv
hf-kklein d6068c4
Merge branch 'main' into use-parsed-kv
hf-kklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """contains the Kommunikationsrichtung model""" | ||
|
|
||
| from fundamend.models.base import FundamendBaseModel | ||
|
|
||
|
|
||
| # needs to be separate file/module to avoid circular imports | ||
| class Kommunikationsrichtung(FundamendBaseModel): | ||
| """ | ||
| a strongly typed representation of the 'Kommunikation_von' attribute of anwendungsfall | ||
| """ | ||
|
|
||
| sender: str #: e.g. "NB" | ||
| empfaenger: str #: e.g. "MSB" | ||
|
|
||
|
|
||
| __all__ = ["Kommunikationsrichtung"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
|
|
||
|
|
||
| try: | ||
| from sqlalchemy import CheckConstraint, UniqueConstraint | ||
| from sqlalchemy import JSON, CheckConstraint, Column, UniqueConstraint | ||
| from sqlmodel import Field, Relationship, SQLModel | ||
| except ImportError as import_error: | ||
| import_error.msg += "; Did you install fundamend[sqlmodels] or did you try to import from fundamend.models instead?" | ||
|
|
@@ -341,6 +341,15 @@ class Anwendungsfall(SQLModel, table=True): | |
| pruefidentifikator: str = Field(index=True) #: e.g. '25001' | ||
| beschreibung: str = Field(index=True) #: e.g. 'Berechnungsformel' | ||
| kommunikation_von: str #: e.g. 'NB an MSB / LF' | ||
| kommunikationsrichtungen: list[dict[str, str]] | None = Field(default=None, sa_column=Column(JSON)) | ||
|
||
| """ | ||
| JSON column containing a list of dicts with keys 'sender' and 'empfaenger'. | ||
| The columns value can be deserialized as list[Kommunikationsrichtung]. | ||
| The column contains no more information than the stringly typed 'kommunikation_von' column alone, | ||
| but it's parsed already and hence easier to use and query. | ||
| """ | ||
| # we use a json column because setting up a separate table and FK relationships for this seems overkill | ||
| # https://stackoverflow.com/a/70659555/10009545 | ||
| format: EdifactFormat = Field(index=True) #: e.g. 'UTILTS' | ||
| segments: list[Segment] = Relationship(back_populates="anwendungsfall") | ||
| segment_groups: list[SegmentGroup] = Relationship(back_populates="anwendungsfall") | ||
|
|
@@ -356,6 +365,11 @@ def from_model(cls, model: PydanticAnwendungsfall, position: Optional[int] = Non | |
| pruefidentifikator=model.pruefidentifikator, | ||
| beschreibung=model.beschreibung, | ||
| kommunikation_von=model.kommunikation_von, | ||
| kommunikationsrichtungen=( | ||
| [kr.model_dump(mode="json") for kr in model.kommunikationsrichtungen] | ||
| if model.kommunikationsrichtungen is not None | ||
| else None | ||
| ), | ||
| format=model.format, | ||
| position=position, | ||
| ) | ||
|
|
@@ -373,6 +387,7 @@ def to_model(self) -> PydanticAnwendungsfall: | |
| pruefidentifikator=self.pruefidentifikator, | ||
| beschreibung=self.beschreibung, | ||
| kommunikation_von=self.kommunikation_von, | ||
| # the kommunikationsrichtungen are a computed property, so we reconstruct it from the kommunikation_von str | ||
| format=self.format, | ||
| elements=tuple( | ||
| x.to_model() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra '(l)' character in the docstring.