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

list_models() of dataset containing a BigQuery AutoML models errors with Invalid enum value AUTOML_REGRESSOR for enum type #293

Closed
romainr opened this issue Oct 3, 2020 · 8 comments · Fixed by #328
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@romainr
Copy link

romainr commented Oct 3, 2020

Listing standard BigQuery models (e.g. LINEAR_REGRESSION or https://cloud.google.com/bigquery-ml/docs/bigqueryml-mf-explicit-tutorial#run_the_create_model_query) works, but AutoML model (https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-automl#create_model_syntax) seems to fail?

Environment details

  • OS type and version: Ubuntu 20.04
  • Python version: Python 3.8.2 (default, Jul 16 2020, 14:00:26)
  • pip version: pip 20.2
pip3 freeze | grep goo
google-api-core==1.22.3
google-auth==1.22.0
google-cloud-bigquery==2.0.0
google-cloud-core==1.4.2
google-crc32c==1.0.0
google-resumable-media==1.0.0
googleapis-common-protos==1.6.0

Steps to reproduce

  1. Create a BigQuery AutoML model, e.g. https://cloud.google.com/bigquery-ml/docs/bigqueryml-mf-explicit-tutorial
  2. Use the API to list the models

Code example

from google.cloud import bigquery

client = bigquery.Client()                
                
for d in client.list_datasets():
  for m in client.list_models(d.reference):
    print(m.friendly_name)

Stack trace

Traceback (most recent call last):
  File " python3.8/site-packages/google/protobuf/json_format.py", line 745, in _ConvertScalarFieldValue
    number = int(value)
ValueError: invalid literal for int() with base 10: 'AUTOML_REGRESSOR'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File " python3.8/site-packages/google/protobuf/json_format.py", line 589, in _ConvertFieldValuePair
    setattr(message, field.name, _ConvertScalarFieldValue(value, field))
  File " python3.8/site-packages/google/protobuf/json_format.py", line 748, in _ConvertScalarFieldValue
    raise ParseError('Invalid enum value {0} for enum type {1}.'.format(
google.protobuf.json_format.ParseError: Invalid enum value AUTOML_REGRESSOR for enum type google.cloud.bigquery.v2.Model.ModelType.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File " python3.8/site-packages/google/api_core/page_iterator.py", line 213, in _items_iter
    for item in page:
  File " python3.8/site-packages/google/api_core/page_iterator.py", line 133, in next
    result = self._item_to_value(self._parent, item)
  File " python3.8/site-packages/google/cloud/bigquery/client.py", line 3241, in _item_to_model
    return Model.from_api_repr(resource)
  File " python3.8/site-packages/google/cloud/bigquery/model.py", line 308, in from_api_repr
    this._proto = json_format.ParseDict(
  File " python3.8/site-packages/google/protobuf/json_format.py", line 452, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File " python3.8/site-packages/google/protobuf/json_format.py", line 483, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File " python3.8/site-packages/google/protobuf/json_format.py", line 592, in _ConvertFieldValuePair
    raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
google.protobuf.json_format.ParseError: Failed to parse modelType field: Invalid enum value AUTOML_REGRESSOR for enum type google.cloud.bigquery.v2.Model.ModelType..
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Oct 3, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Oct 4, 2020
@HemangChothani HemangChothani added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Oct 5, 2020
@HemangChothani HemangChothani self-assigned this Oct 5, 2020
@HemangChothani
Copy link
Contributor

@romainr Thanks for the report, I am able to reproduce it.
@tswast This is is related to gapic (autogen) files, I found the enum mapping for LINEAR_REGRESSION and others in types/model.py, but not able to found for the AUTOML_REGRESSOR so, when protobuf trying to fetch enum value it gets None value and failed at the time of int conversion.

I think it's external issue.

@tswast
Copy link
Contributor

tswast commented Oct 5, 2020

We're working on refreshing the protocol buffers at https://github.com/googleapis/googleapis/tree/master/google/cloud/bigquery/v2 which are used to generate this code.

@romainr does this happen at the time of list_models() or when the enum property is accessed? I wonder if it would be a useful workaround in the meantime to add some lazy parsing logic to this generated code to not fail on missing enum values?

CC @shollyman

@HemangChothani
Copy link
Contributor

It happen when we execute list(list_models()) line, I have assigned a static number when it tried to fetch enum_value by the name and it works fine.

@romainr
Copy link
Author

romainr commented Oct 5, 2020

Thanks for confirming!

In the meantime, @HemangChothani, would you be able to share your "workaround"?

@HemangChothani
Copy link
Contributor

@romainr What i have done is just to check the actual cause of error, it's not the right way to solve it like to edit generated code files and proto files.

@tswast tswast added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: question Request for information or clarification. Not an issue. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Oct 9, 2020
@tswast
Copy link
Contributor

tswast commented Oct 15, 2020

We finally published the protocol buffers for this feature and it has made its way to a PR in #328

Before we merge that, I'd like to merge #316 and #319 as the code generator made a breaking change, which I'd like to make worth it by actually improving the experience in the subsequent 3.0 release

@skelliest
Copy link

Thank you! Just when I wanted to access my new models!

@stokvis4
Copy link

stokvis4 commented May 5, 2022

Code:

from google.cloud import bigquery

# Construct a BigQuery client object.
client = bigquery.Client()

# TODO(developer): Set dataset_id to the ID of the dataset that contains
#                  the models you are listing.
dataset_id = '<project>.model_tables'

models = client.list_models(dataset_id)  # Make an API request.

print("Models contained in '{}':".format(dataset_id))
for model in models:
    full_model_id = "{}.{}.{}".format(
        model.project, model.dataset_id, model.model_id
    )
    friendly_name = model.friendly_name
    print("{}: friendly_name='{}'".format(full_model_id, friendly_name))

Trace:

ValueError                                Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/google/protobuf/json_format.py in _ConvertScalarFieldValue(value, field, require_str)
    749           return number
--> 750         raise ParseError('Invalid enum value {0} for enum type {1}.'.format(
    751             value, field.enum_type.full_name))

ValueError: invalid literal for int() with base 10: 'ARIMA_PLUS'

During handling of the above exception, another exception occurred:

ParseError                                Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/google/protobuf/json_format.py in _ConvertFieldValuePair(self, js, message)
    593       except TypeError as e:
--> 594         raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
    595 

~/opt/anaconda3/lib/python3.8/site-packages/google/protobuf/json_format.py in _ConvertScalarFieldValue(value, field, require_str)
    752     return enum_value.number
--> 753 
    754 

ParseError: Invalid enum value ARIMA_PLUS for enum type google.cloud.bigquery.v2.Model.ModelType.

During handling of the above exception, another exception occurred:

ParseError                                Traceback (most recent call last)
<ipython-input-47-076c48a53963> in <module>
     11 
     12 print("Models contained in '{}':".format(dataset_id))
---> 13 for model in models:
     14     full_model_id = "{}.{}.{}".format(
     15         model.project, model.dataset_id, model.model_id

~/opt/anaconda3/lib/python3.8/site-packages/google/api_core/page_iterator.py in _items_iter(self)
    213     def __iter__(self):
    214         """Iterator for each item returned.
--> 215 
    216         Returns:
    217             types.GeneratorType[Any]: A generator of items from the API.

~/opt/anaconda3/lib/python3.8/site-packages/google/api_core/page_iterator.py in next(self)
    131         result = self._item_to_value(self._parent, item)
    132         # Since we've successfully got the next value from the
--> 133         # iterator, we update the number of remaining.
    134         self._remaining -= 1
    135         return result

~/opt/anaconda3/lib/python3.8/site-packages/google/cloud/bigquery/client.py in _item_to_model(iterator, resource)
   2491                 A :class:`~pandas.DataFrame` containing the data to load.
   2492             destination:
-> 2493                 The destination table to use for loading the data. If it is an
   2494                 existing table, the schema of the :class:`~pandas.DataFrame`
   2495                 must match the schema of the destination table. If the table

~/opt/anaconda3/lib/python3.8/site-packages/google/cloud/bigquery/model.py in from_api_repr(cls, resource)
    283         """Factory: construct a model resource given its API representation
    284 
--> 285         Args:
    286             resource (Dict[str, object]):
    287                 Model resource representation from the API

~/opt/anaconda3/lib/python3.8/site-packages/google/protobuf/json_format.py in ParseDict(js_dict, message, ignore_unknown_fields, descriptor_pool)
    452 class _Parser(object):
    453   """JSON format parser for protocol message."""
--> 454 
    455   def __init__(self, ignore_unknown_fields, descriptor_pool):
    456     self.ignore_unknown_fields = ignore_unknown_fields

~/opt/anaconda3/lib/python3.8/site-packages/google/protobuf/json_format.py in ConvertMessage(self, value, message)
    483       message: A regular protocol message to record the data.
    484 
--> 485     Raises:
    486       ParseError: In case of problems converting.
    487     """

~/opt/anaconda3/lib/python3.8/site-packages/google/protobuf/json_format.py in _ConvertFieldValuePair(self, js, message)
    595 
    596   def _ConvertAnyMessage(self, value, message):
--> 597     """Convert a JSON representation into Any message."""
    598     if isinstance(value, dict) and not value:
    599       return

ParseError: Failed to parse modelType field: Invalid enum value ARIMA_PLUS for enum type google.cloud.bigquery.v2.Model.ModelType..

We're unable to use list_models to look at our models and are encountering the issue above without resolve.

Package Versions:

protobuf==3.19.4
google-cloud-bigquery==2.34.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
6 participants