-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1229 Allow return null in kafka Serializer (delete messages aka Tombstones) #1230
Conversation
…es aka Tombstone)
There are some errors in automated tests like:
But that looks like can't be introduced by my change. Could it be possible just restart failed actions? |
Seems like too high version of See https://github.com/guzzle/psr7#upgrading-from-function-api. And yeah, it's outside of the scope of change. EDIT: It seems to be coming from external library, https://github.com/ratchetphp/Pawl. EDIT2: |
@Steveb-p, thank you for the answer.
So, could you please review the change itself? That is very simple I think. |
pkg/rdkafka/JsonSerializer.php
Outdated
if (null !== $string) { | ||
$data = json_decode($string, true); | ||
if (\JSON_ERROR_NONE !== json_last_error()) { | ||
throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg())); | ||
} | ||
} else { | ||
$data = ['body' => null, 'properties' => null, 'headers' => 'headers']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer early return for readability:
if (null !== $string) { | |
$data = json_decode($string, true); | |
if (\JSON_ERROR_NONE !== json_last_error()) { | |
throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg())); | |
} | |
} else { | |
$data = ['body' => null, 'properties' => null, 'headers' => 'headers']; | |
if (null === $string) { | |
return new RdKafkaMessage(null, null, null); | |
} | |
$data = json_decode($string, true); | |
if (\JSON_ERROR_NONE !== json_last_error()) { | |
throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg())); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, applied.
@@ -6,34 +6,30 @@ | |||
|
|||
class JsonSerializer implements Serializer | |||
{ | |||
public function toString(RdKafkaMessage $message): string | |||
public function toString(RdKafkaMessage $message): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not true, and it would not match with the Stringable
interface that is part of PHP8.
See https://www.php.net/manual/en/class.stringable.php.
public function toString(RdKafkaMessage $message): ?string | |
public function toString(RdKafkaMessage $message): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But Serializer
does not extend Stringable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And Stringable defines interface public __toString(): string
method with two underscores in name, not toString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString
should always return a string, especially since it's based on RdKafkaMessage
and can be thought of as an implementation of Stringable
.
Otherwise I have no further comments, and it looks good to me.
@Steveb-p, That is the main change in that pull request. Without it, there is not possible to write into a topic null value. Is not? |
@Hubbitus I kinda assumed it was, my mistake. |
@Steveb-p, no problem. |
Guys, could we please continue? |
Actually, it's not trivial. It breaks the contract for the interface, so semver would dictate that it should have a major version bump. Unfortunately the enqueue library, similarly to Symfony, has a shared version across all packages, so it's not exactly acceptable to just bump this one package and not the rest. If it were to be released as a minor version, it would cause people that update to have broken builds / applications, so there is probably no solution that covers both your need (of a new functionality, kinda) and dependent applications that do have their own serializers. Do you need this for your own application, or is it for your own library that is re-used by others? If it's an application or internal library, then I suggest you overwrite the dependency with your own fork or rely on your own fork with I hope that a new major version of enqueue is released eventually, but given the current state of the package (makasim, the owner, is currently occupied with projects in other languages and is not actively maintaining the lib) I cannot with good conscience promise that. It's something that probably will need to be discussed outside of this PR. If you need any help with package overwriting, I'll be glad to help. |
Hello. Symfony eventually also should update their dependencies. And said after some time (3-12 months) just drop support of current major version. Thanks for the links about forks, of course, I already was thinking about that, but it looks like just some temporary workaround rather than the solution (in any update I will be forced to do puls, re-bases, and my releases...). |
@Hubbitus the issue is that enqueue has a shared versioning, so introducing a single break should result in bumps in all packages. Which don't have any breaking changes atm (due to no small part the fact that some are simply not actively maintained). Personally, I don't mind, but I'm technically not the owner and I cannot make statements if and when a major version bump will be done. @makasim ? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@makasim, could you please look on it? Is it possible to merge that and create a new version? |
Closes #1229