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
[BEAM-3382] Enforce strictly positive natural numbers for AfterCount timers #4300
Conversation
R: @aaltay |
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.
BEAM-3153 in the title does not seem to be directly related to this change, you can have a different issue for this change.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): |
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.
Perhaps also have a JIRA issue, so that this can be fixed in other sdks.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if count == 0: | |||
raise ValueError("count (%s) must be a non-zero natural number." % count) |
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.
-
Make the error statement match the condition. The condition is not checking for natural numbers either. For example
2.3
would not raise this error even though it is not a natural number. You can rephrase it asmust be a positive number
. -
For string formatting of numbers, you can use
%d
instead of%s
.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if count == 0: |
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.
This is checking for non-zero numbers instead of the positive number. You can change this to count > 0
to check for positive numbers.
17604fb
to
b7de0ec
Compare
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.
Thanks, Ahmet. PTAL.
aaltay wrote:
BEAM-3153 in the title does not seem to be directly related to this change, you can have a different issue for this change.
Done.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if count == 0: |
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.
aaltay wrote:
This is checking for non-zero numbers instead of the positive number. You can change this tocount > 0
to check for positive numbers.
Done.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if count == 0: | |||
raise ValueError("count (%s) must be a non-zero natural number." % count) |
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.
aaltay wrote:
Make the error statement match the condition. The condition is not checking for natural numbers either. For example
2.3
would not raise this error even though it is not a natural number. You can rephrase it asmust be a positive number
.For string formatting of numbers, you can use
%d
instead of%s
.
The reason why I didn't check for non-int was that the proto enforced integers, so 2.3 wouldn't be accepted. But the message was not clear, and as you say, it is cleaner to match the error statement, so I modified it per your suggestion.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): |
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.
aaltay wrote:
Perhaps also have a JIRA issue, so that this can be fixed in other sdks.
I am not sure if it affects other SDKs, but I have now filed BEAM-3382 for sdk-py-core
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if not isinstance(count, int) or count < 1: |
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.
isinstance(count, int)
is over limiting, For example both isinstance(3l, int)
and isinstance(3.0, int)
would result in False
. Even though there is no reason to accept them as valid arguments. I do not not think we need to type check things. Checking for the count < 1
should be enough here.
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.
Thanks, PTAL.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if not isinstance(count, int) or count < 1: |
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.
aaltay wrote:
isinstance(count, int)
is over limiting, For example bothisinstance(3l, int)
andisinstance(3.0, int)
would result inFalse
. Even though there is no reason to accept them as valid arguments. I do not not think we need to type check things. Checking for thecount < 1
should be enough here.
I am not sure if you mean count = "thirty one" or count = "three followed by letter L"
The first is rightfully True and the second is rightfully False, so I don't see the problem with that statement.
count < 1 is not restrictive enough, a user could enter 3.4 and they would only get an obscure message thrown by the protobuf. With the checking above, they get a clear reason of their error.
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.
I meant a long value as in type(3L) = <type 'long'>
. I do not see any reason for not letting users to pass long values here.
2df1e91
to
114fddf
Compare
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.
Thanks, PTAL.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if not isinstance(count, int) or count < 1: |
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.
aaltay wrote:
I meant a long value as intype(3L) = <type 'long'>
. I do not see any reason for not letting users to pass long values here.
It makes sense. I have just incorporated the right change so that long types are allowed while enforcing non-fractional numbers.
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.
Thanks, PTAL.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if not isinstance(count, int) or count < 1: |
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.
aaltay wrote:
I meant a long value as intype(3L) = <type 'long'>
. I do not see any reason for not letting users to pass long values here.
It makes sense. I have just incorporated the right change so that long types are allowed while enforcing non-fractional numbers.
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.
mariapython wrote:
Thanks, PTAL.
Done.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if not isinstance(count, int) or count < 1: |
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.
mariapython wrote:
It makes sense. I have just incorporated the right change so that long types are allowed while enforcing non-fractional numbers.
This will still fail for float types like 3.0
but I think that is fine, we do not need to make more changes here.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if count == 0: | |||
raise ValueError("count (%s) must be a non-zero natural number." % count) |
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.
mariapython wrote:
The reason why I didn't check for non-int was that the proto enforced integers, so 2.3 wouldn't be accepted. But the message was not clear, and as you say, it is cleaner to match the error statement, so I modified it per your suggestion.
Could you change there error string to count (%d) must be a positive integer.
?
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): |
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.
mariapython wrote:
I am not sure if it affects other SDKs, but I have now filed BEAM-3382 for sdk-py-core
Done.
@@ -378,6 +378,8 @@ class AfterCount(TriggerFn): | |||
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn()) | |||
|
|||
def __init__(self, count): | |||
if count == 0: | |||
raise ValueError("count (%s) must be a non-zero natural number." % count) |
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.
aaltay wrote:
Could you change there error string tocount (%d) must be a positive integer.
?
Done.
114fddf
to
18c4162
Compare
LGTM, I can merge after tests pass. |
retest this please |
Tests seemingly failed for unrelated timeouts. I want to rerun tests again. Asked Jenkins to re-trigger the tests. |
No description provided.