eclipse-cyclonedds / eclipse-cyclonedds/cyclonedds-python
Exception while using annotation hashid
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 110
- Forks
- 68
- Avg merge
- 1h 8m
- Merged PRs (30d)
- 1
Description
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 ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in cyclonedds/idl/_main.py at the md5 expression shown in the report, then reproduce the failure by defining PersonHashid with annotate.member_hash_id and initializing its Topic. Check the hash-id handling for the string annotation and verify that Topic initialization completes without the TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 57/100