Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Exception while using annotation hashid

未关闭
#230 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
57/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python

调研方向

从报告中显示的 md5 表达式开始,在 cyclonedds/idl/_main.py 中操作,然后通过使用 annotate.member_hash_id 定义 PersonHashid 并初始化其 Topic 来复现该故障。检查字符串注解的 hash-id 处理,并验证 Topic 初始化能够在没有 TypeError 的情况下完成。

由索引模型根据 Issue 内容生成。

描述

When I use hash annotations to modify the dataclass field, I throw an exception: TypeError: Strings must be encoded before hashing
My dataclass is:
@dataclass
class PersonHashid(idl.IdlStruct, typename="PersonHashid"):
name: str
annotate.member_hash_id("name", "123")
age: types.int32
address: str

An exception occurred when I used the following code to initialize the topic :
participant = DomainParticipant(0)
topic = Topic(participant,"HelloWorldTopic", PersonHashid)

Abnormal information:
mid = unpack("<I", md5(f_annot.get("hash_id", "") or name.encode()).digest()[:4])[0] & 0x0FFFFFFF
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Strings must be encoded before hashing

After tracking the code, it was found that the problem occurred in the file cyclonedds/idl/_main. py: mid=unpack ("<I", md5 (f-annot. get ("hash_id", "") or name. encode()). digest() [: 4]) [0]&0x0FFFFFFF

Is the correct code supposed to be: mid=unpack ("<I", md5 ((f-annot. get ("hash_id", "") or name). encode()). digest() [: 4]) [0]&0x0FFFFFFF ?

主要语言
Python
星标
110
派生
68
平均合并
3 天 5 小时
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

eclipse-cyclonedds/cyclonedds-python 的其他 Issue

查看 eclipse-cyclonedds/cyclonedds-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。