Skip to content

Conversation

@degerahmet
Copy link

@degerahmet degerahmet commented Mar 18, 2025

Issue #556

This pull request includes several changes to the faust library, specifically in the faust/app/base.py and faust/tables/base.py files. The most important changes involve the addition of a value_serializer parameter to various methods and the correction of a minor typo.

Additions of value_serializer parameter:

  • faust/app/base.py: Added value_serializer parameter to the Table method and included it in the method's body. [1] [2]
  • faust/tables/base.py: Added value_serializer parameter to the __init__ method of the Table class and used it in place of the previous value serializer assignment. [1] [2]
  • faust/tables/base.py: Included value_serializer in the _new_store_by_url method.

Minor typo correction:

EDIT

Title

Fix value_serializer Issue in send_soon Method and Add Error Handling for None Event in _send_changelog

Description

This PR resolves an issue where the value_serializer was not properly set in the send_soon method, leading to an AssertionError during testing. Additionally, it enhances error handling in the _send_changelog method by explicitly raising a RuntimeError if the event parameter is None.

These changes ensure more robust behavior and prevent silent failures when processing changelog events.

Changes Made

File: faust/tables/base.py

  • Fixed: Ensured value_serializer is correctly set in the send_soon method.
  • Enhanced: Added a safeguard in _send_changelog to check for None events and raise a RuntimeError if encountered.
  • Updated: Set default values for key_serializer and value_serializer to 'json' in _send_changelog to prevent serialization issues.

File: tests/unit/tables/test_base.py

  • Updated: The test_send_changelog method now verifies that value_serializer is correctly set.
  • Added: A new test case to ensure a RuntimeError is raised when event is None in _send_changelog.

Testing

  • Ran all unit tests in tests/unit/tables/test_base.py to confirm no regressions.
  • Verified that value_serializer defaults to 'json' and is correctly assigned in send_soon.
  • Confirmed that _send_changelog raises a RuntimeError when event is None.

Related Issues

Fixes #556

Checklist

✅ Code changes are complete.
✅ Unit tests have been updated to cover the changes.
✅ All tests pass locally.
✅ Documentation has been updated (if applicable).

# Fallback to json
self.key_serializer = self._serializer_from_type(self.key_type)
self.value_serializer = self._serializer_from_type(self.value_type)
self.value_serializer = value_serializer # Add this line
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you comment add this line everywhere? seems like a rather invaluable comment

Copy link
Author

Choose a reason for hiding this comment

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

That comment made me remember what I should do. Can I remove these comments if that works for you?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd recommend it as this is not useful anymore IMO

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I've removed them.

window: Optional[WindowT] = None,
partitions: Optional[int] = None,
help: Optional[str] = None,
value_serializer: str = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I did only look into this quickly before but the typing is off here.

Why isn't it Optional[CodecArg] like in the Collections base class?

# Fallback to json
self.key_serializer = self._serializer_from_type(self.key_type)
self.value_serializer = self._serializer_from_type(self.value_type)
self.value_serializer = value_serializer
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not deep in to Tables yet as I have not used them extensively, but it looks like we do lose convenience behaviour here, as the _serializer_from_type functions translates us bytes to raw and sets the default json.

This seems to be a breaking change. can you elaborate the behaviour?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your review. I will make changes

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.

Tables don't accept value_serializer kw

2 participants