Repository: googleapis/google-cloud-python

Issue:
google.cloud.error_reporting AttributeError: 'Client' object has no attribute 'project'
I am trying to follow the sample code [here](https://googlecloudplatform.github.io/google-cloud-python/stable/error-reporting-usage.html) in an appengine custom flexible runtime and whenever I run the code, I get the following error:

```
Traceback (most recent call last):
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1994, in __call__
    return self.wsgi_app(environ, start_response)
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/env/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/env/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/env/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/vmagent/app/xxx.py", line 20, in simulate_error
    ec.report_exception()
  File "/env/lib/python3.5/site-packages/google/cloud/error_reporting/client.py", line 348, in report_exception
    user=user)
  File "/env/lib/python3.5/site-packages/google/cloud/error_reporting/client.py", line 277, in _send_error_report
    self.report_errors_api.report_error_event(error_report)
  File "/env/lib/python3.5/site-packages/google/cloud/error_reporting/client.py", line 162, in report_errors_api
    self._report_errors_api = make_report_error_api(self)
  File "/env/lib/python3.5/site-packages/google/cloud/error_reporting/_gax.py", line 44, in make_report_error_api
    return _ErrorReportingGaxApi(gax_client, client.project)
AttributeError: 'Client' object has no attribute 'project'
```
In the same project I'm also creating clients for pubsub and storage with the same default constructor and they both find the project and credentials, both when running in appengine as well as when I run the container locally and specify credentials by setting GOOGLE_APPLICATION_CREDENTIALS to point to a json file containing credentials for a service account.

I have also tried explicitly passing the project explicitly using something like:

```
ec = error_reporting.Client(project='xyz')
```

and

```
ec = error_reporting.Client('xyz')
```

to no avail.

Here is the sample code that fails:

```
from flask import Flask
from google.cloud import error_reporting


app = Flask(__name__)


@app.route('/simulate_error')
def simulate_error():
    ec = error_reporting.Client()
    try:
        # simulate calling a method that's not defined
        raise NameError
    except Exception:
        ec.report_exception()


if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
```

Here is the output from `pip freeze | grep ^google-cloud`:

```
google-cloud==0.23.0
google-cloud-bigquery==0.23.0
google-cloud-bigtable==0.23.1
google-cloud-core==0.23.1
google-cloud-datastore==0.23.0
google-cloud-dns==0.23.0
google-cloud-error-reporting==0.23.1
google-cloud-language==0.23.1
google-cloud-logging==0.23.1
google-cloud-monitoring==0.23.0
google-cloud-pubsub==0.23.0
google-cloud-resource-manager==0.23.0
google-cloud-runtimeconfig==0.23.0
google-cloud-spanner==0.23.1
google-cloud-speech==0.23.0
google-cloud-storage==0.23.1
google-cloud-translate==0.23.0
google-cloud-vision==0.23.3
```


Discussion:
forgot to mention I get a similar error when I try to use the google.cloud.logging client as well.
Thanks for reporting, @cva. :-) Looking into this now.

Resolving patch:
diff --git a/error_reporting/google/cloud/error_reporting/client.py b/error_reporting/google/cloud/error_reporting/client.py
--- a/error_reporting/google/cloud/error_reporting/client.py
+++ b/error_reporting/google/cloud/error_reporting/client.py
@@ -23,7 +23,7 @@
 except ImportError:  # pragma: NO COVER
     _HAVE_GAX = False
 
-from google.cloud._helpers import _determine_default_project
+from google.cloud.client import ClientWithProject
 from google.cloud.error_reporting._logging import _ErrorReportingLoggingAPI
 from google.cloud.environment_vars import DISABLE_GRPC
 
@@ -74,7 +74,7 @@ def __init__(self, method=None, url=None,
         self.remoteIp = remote_ip
 
 
-class Client(object):
+class Client(ClientWithProject):
     """Error Reporting client. Currently Error Reporting is done by creating
     a Logging client.
 
@@ -125,13 +125,8 @@ def __init__(self, project=None,
                  service=None,
                  version=None,
                  use_gax=None):
-        if project is None:
-            self._project = _determine_default_project()
-        else:
-            self._project = project
-        self._credentials = credentials
-        self._http = http
-
+        super(Client, self).__init__(project=project, credentials=credentials,
+                                     http=http)
         self._report_errors_api = None
 
         self.service = service if service else self.DEFAULT_SERVICE
@@ -162,7 +157,7 @@ def report_errors_api(self):
                 self._report_errors_api = make_report_error_api(self)
             else:
                 self._report_errors_api = _ErrorReportingLoggingAPI(
-                    self._project, self._credentials, self._http)
+                    self.project, self._credentials, self._http)
         return self._report_errors_api
 
     def _build_error_report(self,


Test patch:
diff --git a/error_reporting/unit_tests/test_client.py b/error_reporting/unit_tests/test_client.py
--- a/error_reporting/unit_tests/test_client.py
+++ b/error_reporting/unit_tests/test_client.py
@@ -52,14 +52,14 @@ def _get_report_payload(self, error_api):
         self.assertEqual(len(positional), 1)
         return positional[0]
 
-    @mock.patch(
-        'google.cloud.error_reporting.client._determine_default_project')
+    @mock.patch('google.cloud.client._determine_default_project')
     def test_ctor_default(self, default_mock):
         credentials = _make_credentials()
+        default_mock.return_value = 'foo'
         client = self._make_one(credentials=credentials)
         self.assertEqual(client.service, client.DEFAULT_SERVICE)
         self.assertEqual(client.version, None)
-        default_mock.assert_called_once_with()
+        default_mock.assert_called_once_with(None)
 
     def test_ctor_params(self):
         credentials = _make_credentials()