IDL inheritance causes runtime errors during Topic creation
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu trong cyclonedds/idl/_xt_builder.py tại _xt_minimal_struct_header và _xt_complete_struct_header, sau đó tái hiện lỗi bằng ví dụ foo.idl Parent/Child và việc tạo Topic được nêu trong issue. Hoàn tất khi các kiểu IDL kế thừa có thể tạo các Topic Parent và Child, đồng thời ghi/đọc các thực thể Child mà không có lỗi hoặc assertion của DDS.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hello!
I'm experiencing the following issue with the code generated from IDL definitions that use inheritance
foo.idl
struct Parent {
long parent1;
};
struct Child : Parent {
long child1;
};
Generate code from IDL via idlc:
"""
Generated by Eclipse Cyclone DDS idlc Python Backend
Cyclone DDS IDL version: v0.11.0
Module:
IDL file: foo.idl
"""
from dataclasses import dataclass
from enum import auto
from typing import TYPE_CHECKING, Optional
import cyclonedds as dds
import cyclonedds.idl as idl
import cyclonedds.idl.annotations as annotate
import cyclonedds.idl.types as types
@dataclass
@annotate.final
@annotate.autoid("sequential")
class Parent(idl.IdlStruct, typename="Parent"):
parent1: types.int32
@dataclass
@annotate.final
@annotate.autoid("sequential")
class Child(Parent, typename="Child"):
child1: types.int32
Parent class instead of idl.IdlStruct in Python was fixed in https://github.com/eclipse-cyclonedds/cyclonedds-python/issues/162. The change also added some additional checks for base classes. However, trying to use the code (with main branch of the core library (d6684dc96e7ef092869688358753e49e33e9bbc2) fails, for example
"""
Generated by Eclipse Cyclone DDS idlc Python Backend
Cyclone DDS IDL version: v0.11.0
Module:
IDL file: foo.idl
"""
from dataclasses import dataclass
from enum import auto
from typing import TYPE_CHECKING, Optional
import cyclonedds as dds
import cyclonedds.idl as idl
import cyclonedds.idl.annotations as annotate
import cyclonedds.idl.types as types
@dataclass
@annotate.final
@annotate.autoid("sequential")
class Parent(idl.IdlStruct, typename="Parent"):
parent1: types.int32
@dataclass
@annotate.final
@annotate.autoid("sequential")
class Child(Parent, typename="Child"):
child1: types.int32
d = dds.domain.DomainParticipant(42)
t = dds.topic.Topic(d, "test_topic", Child)
w = dds.pub.DataWriter(d, t)
r = dds.sub.DataReader(d, t)
w.write(Child(parent1=1, child1=2))
print(r.read())
$ python foo.py
Traceback (most recent call last):
File "<...>/cyclonedds-python/a/a.py", line 35, in <module>
t = dds.topic.Topic(d, "test_topic", Child)
File "<...>/cyclonedds-python/.venv/lib/python3.10/site-packages/cyclonedds/topic.py", line 59, in __init__
super().__init__(
File "<...>/cyclonedds-python/.venv/lib/python3.10/site-packages/cyclonedds/core.py", line 181, in __init__
raise DDSException(
cyclonedds.core.DDSException: [DDS_RETCODE_BAD_PARAMETER] Bad parameter value. Occurred upon initialisation of a cyclonedds.topic.Topic
Interestingly, if you create a different topic with the Parent class, another error occurs, seemingly because some registration happens in the native DDS:
"""
Generated by Eclipse Cyclone DDS idlc Python Backend
Cyclone DDS IDL version: v0.11.0
Module:
IDL file: foo.idl
"""
from dataclasses import dataclass
from enum import auto
from typing import TYPE_CHECKING, Optional
import cyclonedds as dds
import cyclonedds.idl as idl
import cyclonedds.idl.annotations as annotate
import cyclonedds.idl.types as types
@dataclass
@annotate.final
@annotate.autoid("sequential")
class Parent(idl.IdlStruct, typename="Parent"):
parent1: types.int32
@dataclass
@annotate.final
@annotate.autoid("sequential")
class Child(Parent, typename="Child"):
child1: types.int32
d = dds.domain.DomainParticipant(42)
t_parent = dds.topic.Topic(d, "test_parent", Parent)
t = dds.topic.Topic(d, "test_topic", Child)
w = dds.pub.DataWriter(d, t)
r = dds.sub.DataReader(d, t)
w.write(Child(parent1=1, child1=2))
print(r.read())
$ python foo.py
python: <...>/cyclonedds/src/core/ddsi/src/ddsi_typewrap.c:3112: ddsi_xt_get_typeobject_kind_impl: Assertion `xt->kind == DDSI_TYPEID_KIND_COMPLETE' failed.
Aborted (core dumped)
I've tried digging around the code and I believe I might see the issue. My understanding of the XT type encoding is practically nonexistent, but it seems that the Child class has the wrong type information in the header section, since it points to the minimal version of the Parent class instead of the complete one. The following diff makes the script above working properly:
diff --git a/cyclonedds/idl/_xt_builder.py b/cyclonedds/idl/_xt_builder.py
index 37a5453..19010c1 100644
--- a/cyclonedds/idl/_xt_builder.py
+++ b/cyclonedds/idl/_xt_builder.py
@@ -905,7 +905,7 @@ class XTBuilder:
@classmethod
def _xt_minimal_struct_header(cls, entity: Type[IdlStruct]) -> xt.MinimalStructHeader:
- if entity.__base__ is None or entity.__base__ == IdlStruct:
+ if entity.__base__ is None or issubclass(entity.__base__, IdlStruct):
return xt.MinimalStructHeader(
base_type=xt.TypeIdentifier(discriminator=xt.TK_NONE, value=None),
detail=cls._xt_minimal_type_detail(entity)
@@ -918,7 +918,7 @@ class XTBuilder:
@classmethod
def _xt_complete_struct_header(cls, entity: Type[IdlStruct]) -> xt.CompleteStructHeader:
- if entity.__base__ is None or entity.__base__ == IdlStruct:
+ if entity.__base__ is None or issubclass(entity.__base__, IdlStruct):
return xt.CompleteStructHeader(
base_type=xt.TypeIdentifier(discriminator=xt.TK_NONE, value=None),
detail=cls._xt_complete_type_detail(entity)
$ python foo.py
[Child(parent1=1, child1=2)]
Hope this might help.
- Ngôn ngữ chính
- Python
- Star
- 110
- Fork
- 68
- Merge trung bình
- 3 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của eclipse-cyclonedds/cyclonedds-python
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
-
Generated Python code is not interoperable when a union contains a member called "value"Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
eclipse-cyclonedds/cyclonedds-python#333 · 1 bình luận ·
Tất cả issue của eclipse-cyclonedds/cyclonedds-python
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
fossasia/visdom-dev#69 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Frontend build fails with Frappe version-16: DataImport is no longer exported by @framework/uiĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
BUG: PROD: v1.3.0-beta Onboarding Profile Picture Misaligns When Name Validation Error AppearsCó thể đã có người làm @RitikaSen27 đã nhận hôm nay. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
AOSSIE-Org/PictoPy#1647 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[oblt-aw][autodoc] Update workflow docs for gh-aw v0.92.5 and detector permission scopeCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày