-
Notifications
You must be signed in to change notification settings - Fork 43
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
Fix Py4JJavaError serialization issue #60
Conversation
Documentation update.
0.1.33 Release
Release 0.1.33
* Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]>
@@ -30,6 +34,9 @@ def append(self, testresult): | |||
self.total_execution_time = total_execution_time | |||
|
|||
def serialize(self): | |||
for i in self.results: | |||
if isinstance(i.exception, Py4JJavaError): | |||
i.exception = Exception(str(i.exception)) |
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 may limit the error info. Perhaps it would be better to use traceback.format_exception
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.
From the Py4J documentation, "str(py4j_java_error) returns the error message and the stack trace available on the Java side (similar to printStackTrace())." It seemed to be the simplest way to capture the original (Java) error message and stack trace.
Here is an example of what the output looks like after serialising/deserialising the exception:
foo = result.test_results.serialize()
bar = TestResults().deserialize(foo)
print(bar.results[0].exception)
Result:
An error occurred while calling o415._run.
: com.databricks.WorkflowException: com.databricks.NotebookExecutionException: FAILED
at com.databricks.workflow.WorkflowDriver.run(WorkflowDriver.scala:71)
at com.databricks.dbutils_v1.impl.NotebookUtilsImpl.run(NotebookUtilsImpl.scala:122)
at com.databricks.dbutils_v1.impl.NotebookUtilsImpl._run(NotebookUtilsImpl.scala:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:380)
at py4j.Gateway.invoke(Gateway.java:295)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:251)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.databricks.NotebookExecutionException: FAILED
at com.databricks.workflow.WorkflowDriver.run0(WorkflowDriver.scala:117)
at com.databricks.workflow.WorkflowDriver.run(WorkflowDriver.scala:66)
... 13 more
tests/nutter/test_testresult.py
Outdated
def get_py4j_exception(): | ||
# Raise a Py4JJavaError | ||
# NB: a running Py4J Java Gateway is required for this to work. | ||
gateway = JavaGateway() | ||
random = gateway.jvm.java.util.Random() | ||
try: | ||
_ = random.nextInt(-1) | ||
except Py4JJavaError as e: | ||
_ex = e | ||
return _ex |
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.
Would it be possible to just throw a Py4JJavaError
something like this: raise Py4JJavaError()
?
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.
It's unfortunately a bit more complicated, but I found a way to create a Py4JJavaError
by mocking a bunch of other Py4J objects... I pushed the changes and removed the dependency to a real Py4J environment.
Link to SO post for reference: https://stackoverflow.com/questions/58384719/pyspark-mocking-exception-test-succeeds-but-exception-is-not-handled
* Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Fix Py4JJavaError serialization issue * Test Py4JJavaError using mocks * Remove Py4J stuff * Still need to install py4j to run tests Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]>
* Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes * Parallel runner implementation (#59) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Parallel runner * Rename helper class * Fix collect results * Rename execute method * Use new execute method * Introduce add_test_fixture() method Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Fix Py4JJavaError serialization issue (#60) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Fix Py4JJavaError serialization issue * Test Py4JJavaError using mocks * Remove Py4J stuff * Still need to install py4j to run tests Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Add notebook params and debugger (#68) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Add notebook params and debugger * Add example in README.md * Have more explicit notebook_params error message * Revert "Add example in README.md" This reverts commit 1aac73c. * Add examples for notebook params Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> Co-authored-by: Neyissa Exilus <[email protected]> * upgraded python version * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes * Parallel runner implementation (#59) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Parallel runner * Rename helper class * Fix collect results * Rename execute method * Use new execute method * Introduce add_test_fixture() method Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Fix Py4JJavaError serialization issue (#60) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Fix Py4JJavaError serialization issue * Test Py4JJavaError using mocks * Remove Py4J stuff * Still need to install py4j to run tests Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Add notebook params and debugger (#68) * Toc Update (#30) * Release v0.1.34 (#52) * Improved the error message when the call to the parent class constructor is missing in a test fixture * Fixing the Environment variale setting documentation for Windows Powershell * Apply suggestions from code review Co-authored-by: Omri Mendels <[email protected]> * Feature: Discover test files with '_test' suffix (#47) * Enable test discovery for test names with suffix 'test' * Combine redundant suffix tests * Remove old suffix tests * Encapsulate test name parsing and have nuttercli call test name validation from api * Have api client results call _is_valid_test_name from api Co-authored-by: Quan Nguyen <[email protected]> * Invalid State response is retriable (#49) * fixed import error and refactoring * invalid state is retriable, pull sleep is 5 seconds * Poll wait time as flag (#51) * poll wait time as flag * lint fixes Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> * Update README.md * Add notebook params and debugger * Add example in README.md * Have more explicit notebook_params error message * Revert "Add example in README.md" This reverts commit 1aac73c. * Add examples for notebook params Co-authored-by: Jesus Aguilar <[email protected]> Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> Co-authored-by: Neyissa Exilus <[email protected]> * upgraded python version * version bump, python 3.7 * added py4j requirement * doc update * doc update Co-authored-by: RobBagby <[email protected]> Co-authored-by: Prakash Kudkuli Vishnu <[email protected]> Co-authored-by: Omri Mendels <[email protected]> Co-authored-by: quanuw <[email protected]> Co-authored-by: Quan Nguyen <[email protected]> Co-authored-by: Thomas Conté <[email protected]> Co-authored-by: Andrew Francisque <[email protected]> Co-authored-by: Neyissa Exilus <[email protected]>
This is a proposed fix for #46.
If a
Py4JJavaError
is found within test results, it is replaced with a baseException
, copying the error message and stack trace from the original. The original exception is lost, but I think this is OK since the serialisation is performed when the test notebook exits.Regarding tests, unfortunately I could not find a way to reproduce the error via mocks, e.g. without actually using Py4J. Thus the provided test is more of an integration test, since it requires a running Py4J gateway process. The startup script, Java source code, and modified pipeline are provided to set up the environment during CI. If the Py4J environment is not available, the test is skipped.