Skip to content
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

feat: include key metadata in Job representation #964

Merged
merged 1 commit into from Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions google/cloud/bigquery/job/base.py
Expand Up @@ -722,6 +722,14 @@ def cancelled(self):
and self.error_result.get("reason") == _STOPPED_REASON
)

def __repr__(self):
result = (
f"{self.__class__.__name__}<"
f"project={self.project}, location={self.location}, id={self.job_id}"
">"
Comment on lines +727 to +729
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note - I chose chevrons over parentheses so that the repr string does not appear as something eval()-able, as it's often the case with repr() output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thanks.

)
return result


class _JobConfig(object):
"""Abstract base class for job configuration objects.
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/job/test_base.py
Expand Up @@ -1043,6 +1043,12 @@ def test_cancelled_w_error_result_w_stopped(self):

self.assertTrue(job.cancelled())

def test_repr(self):
client = _make_client(project="project-foo")
job = self._make_one("job-99", client)
job._properties.setdefault("jobReference", {})["location"] = "ABC"
assert repr(job) == "_AsyncJob<project=project-foo, location=ABC, id=job-99>"


class Test_JobConfig(unittest.TestCase):
JOB_TYPE = "testing"
Expand Down