potiuk commented on a change in pull request #6749: [AIRFLOW-6193] Do not use 
asserts in Airflow main code
URL: https://github.com/apache/airflow/pull/6749#discussion_r355172746
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/dataproc.py
 ##########
 @@ -232,12 +232,11 @@ def __init__(self,
         self.customer_managed_key = customer_managed_key
         self.single_node = num_workers == 0
 
-        assert not (self.custom_image and self.image_version), \
-            "custom_image and image_version can't be both set"
+        if self.custom_image and self.image_version:
+            raise ValueError("The custom_image and image_version can't be both 
set")
 
-        assert (
-            not self.single_node or (self.single_node and 
self.num_preemptible_workers == 0)
-        ), "num_workers == 0 means single node mode - no preemptibles allowed"
+        if self.num_preemptible_workers == 0 and not self.single_node:
+            raise ValueError("num_workers == 0 means single node mode - no 
preemptibles allowed")
 
 Review comment:
   I was quite a bit confused with the condition :). But you are right:
   
   When you convert assert to if you need to revert the original condition. If 
you do it in the above case using DeMorgan you get:
   `not  (not self.single_node or (self.single_node and 
self.num_preemptible_workers == 0))`
   
   which simplifies to:
   
   `self.single_node and (not self.single_node or self.num_preemptible_workers 
!= 0)`
   
   It will only work indeed when self.single_node is true and 
self.num_preemptible_workers >0
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to