Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend_common_py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
videoag
backend_common_py
Commits
f9e6d08c
Commit
f9e6d08c
authored
5 months ago
by
Simon Künzel
Browse files
Options
Downloads
Patches
Plain Diff
Fix not using variant's subclass when creating objects
parent
4b9984eb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/videoag_common/api_object/object_class.py
+25
-13
25 additions, 13 deletions
src/videoag_common/api_object/object_class.py
with
25 additions
and
13 deletions
src/videoag_common/api_object/object_class.py
+
25
−
13
View file @
f9e6d08c
...
@@ -54,6 +54,7 @@ class ApiObjectClass:
...
@@ -54,6 +54,7 @@ class ApiObjectClass:
self
.
_parent_relationship_id_by_class_id
=
{}
self
.
_parent_relationship_id_by_class_id
=
{}
self
.
_variant_field
:
ApiEnumField
or
None
=
None
self
.
_variant_field
:
ApiEnumField
or
None
=
None
self
.
_orm_classes_by_variant
:
dict
[
str
or
None
,
type
[
ApiObject
]]
=
{}
def
set_class
(
self
,
orm_class
:
type
[
ApiObject
]):
def
set_class
(
self
,
orm_class
:
type
[
ApiObject
]):
self
.
orm_class
=
orm_class
self
.
orm_class
=
orm_class
...
@@ -139,6 +140,9 @@ class ApiObjectClass:
...
@@ -139,6 +140,9 @@ class ApiObjectClass:
if
base_variant_id
is
not
None
and
base_variant_id
not
in
self
.
_variant_field
.
str_enums
:
if
base_variant_id
is
not
None
and
base_variant_id
not
in
self
.
_variant_field
.
str_enums
:
raise
Exception
(
f
"
Class
'
{
self
.
orm_class
.
__name__
}
'
has unknown variant
'
{
base_variant_id
}
'"
)
raise
Exception
(
f
"
Class
'
{
self
.
orm_class
.
__name__
}
'
has unknown variant
'
{
base_variant_id
}
'"
)
if
base_variant_id
is
not
None
:
self
.
_orm_classes_by_variant
[
base_variant_id
]
=
self
.
orm_class
def
_post_init_variant_fields
(
self
,
all_classes
:
dict
[
str
,
"
ApiObjectClass
"
]):
def
_post_init_variant_fields
(
self
,
all_classes
:
dict
[
str
,
"
ApiObjectClass
"
]):
variant_ignore_classes
=
set
(
recursive_flat_map_single
(
lambda
c
:
c
.
__bases__
,
self
.
orm_class
))
variant_ignore_classes
=
set
(
recursive_flat_map_single
(
lambda
c
:
c
.
__bases__
,
self
.
orm_class
))
...
@@ -154,6 +158,8 @@ class ApiObjectClass:
...
@@ -154,6 +158,8 @@ class ApiObjectClass:
raise
Exception
(
f
"
Unknown variant
'
{
variant_id
}
'
for class
'
{
sub_class
.
__name__
}
'
in enum
"
raise
Exception
(
f
"
Unknown variant
'
{
variant_id
}
'
for class
'
{
sub_class
.
__name__
}
'
in enum
"
f
"'
{
self
.
_variant_field
.
enum_class
.
__name__
}
'"
)
f
"'
{
self
.
_variant_field
.
enum_class
.
__name__
}
'"
)
self
.
_orm_classes_by_variant
[
variant_id
]
=
sub_class
# noinspection PyUnresolvedReferences
# noinspection PyUnresolvedReferences
for
super_sub_class
in
set
(
recursive_flat_map_single
(
lambda
c
:
c
.
__bases__
,
sub_class
))
-
variant_ignore_classes
:
for
super_sub_class
in
set
(
recursive_flat_map_single
(
lambda
c
:
c
.
__bases__
,
sub_class
))
-
variant_ignore_classes
:
if
not
hasattr
(
super_sub_class
,
"
__all_class_api_fields__
"
):
if
not
hasattr
(
super_sub_class
,
"
__all_class_api_fields__
"
):
...
@@ -176,6 +182,11 @@ class ApiObjectClass:
...
@@ -176,6 +182,11 @@ class ApiObjectClass:
f
"
API class
'
{
sub2_class
.
__name__
}
'
is indirect child of API class
'
{
self
.
orm_class
.
__name__
}
'
.
"
f
"
API class
'
{
sub2_class
.
__name__
}
'
is indirect child of API class
'
{
self
.
orm_class
.
__name__
}
'
.
"
f
"
Indirect inheritance is not supported (Only direct)
"
)
f
"
Indirect inheritance is not supported (Only direct)
"
)
if
self
.
_variant_field
is
not
None
:
for
variant_id
in
self
.
_variant_field
.
str_enums
:
if
variant_id
not
in
self
.
_orm_classes_by_variant
:
raise
Exception
(
f
"
No ORM class for variant
'
{
variant_id
}
'
of API object class
'
{
self
.
id
}
'"
)
def
_post_init_parents
(
self
,
all_classes
:
dict
[
str
,
"
ApiObjectClass
"
]):
def
_post_init_parents
(
self
,
all_classes
:
dict
[
str
,
"
ApiObjectClass
"
]):
for
parent_relation_id
in
(
self
.
_parent_relationship_config_ids
or
[]):
for
parent_relation_id
in
(
self
.
_parent_relationship_config_ids
or
[]):
parent_relation_attr
=
None
parent_relation_attr
=
None
...
@@ -440,7 +451,18 @@ class ApiObjectClass:
...
@@ -440,7 +451,18 @@ class ApiObjectClass:
if
not
self
.
config_allow_creation
:
if
not
self
.
config_allow_creation
:
raise
Exception
(
"
Creation not allowed
"
)
raise
Exception
(
"
Creation not allowed
"
)
if
self
.
_variant_field
is
not
None
:
if
variant_id
is
None
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
Missing object variant
"
))
if
variant_id
not
in
self
.
_variant_field
.
str_enums
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
Unknown object variant
"
))
obj
=
self
.
_orm_classes_by_variant
[
variant_id
]()
else
:
if
variant_id
is
not
None
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
This object may have no variant
"
))
obj
=
self
.
orm_class
()
obj
=
self
.
orm_class
()
parent_class
=
None
parent_class
=
None
if
len
(
self
.
_parent_relationship_id_by_class_id
)
>
0
:
if
len
(
self
.
_parent_relationship_id_by_class_id
)
>
0
:
if
parent_class_id
is
None
:
if
parent_class_id
is
None
:
...
@@ -464,22 +486,12 @@ class ApiObjectClass:
...
@@ -464,22 +486,12 @@ class ApiObjectClass:
if
parent_class_id
is
not
None
or
parent_id
is
not
None
:
if
parent_class_id
is
not
None
or
parent_id
is
not
None
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
This object may have no parent
"
))
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
This object may have no parent
"
))
if
self
.
_variant_field
is
not
None
:
if
variant_id
is
None
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
Missing object variant
"
))
if
variant_id
not
in
self
.
_variant_field
.
str_enums
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
Unknown object variant
"
))
self
.
_variant_field
.
config_set_value
(
session
,
obj
,
CJsonValue
(
variant_id
))
else
:
if
variant_id
is
not
None
:
raise
ApiClientException
(
ERROR_OBJECT_ERROR
(
"
This object may have no variant
"
))
from
videoag_common.objects
import
ChangelogModificationEntry
,
ChangelogCreationEntry
from
videoag_common.objects
import
ChangelogModificationEntry
,
ChangelogCreationEntry
changelog_entries
:
list
[
ChangelogModificationEntry
]
=
[]
changelog_entries
:
list
[
ChangelogModificationEntry
]
=
[]
remaining_value_keys
=
set
(
values
.
keys
())
remaining_value_keys
=
set
(
values
.
keys
())
for
var
iant
_id
in
{
variant_id
,
None
}:
for
var_id
in
{
variant_id
,
None
}:
for
field
in
self
.
_fields_by_variant_by_config_id
[
var
iant
_id
].
values
():
for
field
in
self
.
_fields_by_variant_by_config_id
[
var_id
].
values
():
if
field
is
self
.
_variant_field
:
if
field
is
self
.
_variant_field
:
continue
continue
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment