Skip to content

Conversation

@teodordelibasic-db
Copy link
Collaborator

@teodordelibasic-db teodordelibasic-db commented Nov 12, 2025

What changes are proposed in this pull request?

Introduce type widening for the type of records the ingest_record method accepts to dict/string for JSON and Message/bytes for Protobuf.

How is this tested?

New tests, manual and examples.

elenagaljak-db
elenagaljak-db previously approved these changes Dec 1, 2025
Copy link
Collaborator

@elenagaljak-db elenagaljak-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, although I am starting to second guess the decision of sending JSON records as dictionaries

Signed-off-by: teodordelibasic-db <[email protected]>
@teodordelibasic-db teodordelibasic-db changed the title Fix JSON examples Type widening for accepted records Dec 18, 2025
offset1 = await ack1
self.assertEqual(offset1, 0)

ack2 = await stream.ingest_record(json.dumps({"device_name": "device2", "temp": 22, "humidity": 55}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add tests for every value type we support

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

elif self._options.record_type == RecordType.JSON:
if not isinstance(record, dict):
if isinstance(record, dict):
serialized_record = json.dumps(record).encode("utf-8")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try catch json dumps? Example if user provides nested custom classes etc, this will raise an exception. Maybe we want to wrap it into our error handling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

Signed-off-by: teodordelibasic-db <[email protected]>
Signed-off-by: teodordelibasic-db <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants