You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BigQuery: The sample to create a BigQuery table is not working #8703
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shahins/.virtualenvs/dl2/lib/python2.7/site-packages/google/cloud/bigquery/table.py", line 370, in __init__
self._properties = {"tableReference": table_ref.to_api_repr(), "labels": {}}
AttributeError: 'str' object has no attribute 'to_api_repr'
(the line that throws this exception is bigquery.Table(.....))
Making sure to follow these steps will guarantee the quickest resolution possible.
This is still an issue, unfortunately. Here is the code that is causing the issue, but with changes to it that I believe fix it, at least in my case. Could someone please take a look at the code and consider this approach as a fix? Without a solution to this issue loading schema files through bigquery.Table will not work with RECORD. I'm not entirely sure about STRUCT, but I assume that would be screened at QA. Thanks...
( from lib/python3.8/site-packages/google/cloud/bigquery/schema.py )
def to_api_repr(self) -> dict:
"""Return a dictionary representing this schema field.
Returns:
Dict: A dictionary representing the SchemaField in a serialized form.
"""
answer = self._properties.copy()
# If this is a RECORD type, then sub-fields are also included,
# add this to the serialized representation.
if self.field_type.upper() in _STRUCT_TYPES:
# answer["fields"] = [f.to_api_repr() for f in self.fields]
answer["fields"] = ""
for f in self.fields: answer["fields"]+=f
answer["fields"] = list(eval(answer["fields"]))
# Done; return the serialized dictionary.
return answer
Activity
ryanyuan commentedon Jul 18, 2019
I believe this has been fixed since 1.10.0 by having a string check in Table.init().
tseaver commentedon Jul 18, 2019
@ryanyuan is correct: the
Tableconstructor has accepted strings formatted in that form since PR #7483 was merged, included in thegoogle-cloud-bigquery 1.10.0releasephilippabaliman commentedon Aug 5, 2020
Still having the same issue on v1.26.1
ryanyuan commentedon Aug 7, 2020
@philippabaliman No issue for me with google-cloud-bigquery==1.26.1. Can you post your stacktrace here?
ikendoit commentedon Nov 28, 2020
check if when you assign a variables like table name, it is an actual string type.
I had this error too, because I had this line:
notice the accidental comma at the end. That would make the variable to be tuple type instead of string.
nlarge-google commentedon Nov 17, 2022
This is still an issue, unfortunately. Here is the code that is causing the issue, but with changes to it that I believe fix it, at least in my case. Could someone please take a look at the code and consider this approach as a fix? Without a solution to this issue loading schema files through bigquery.Table will not work with RECORD. I'm not entirely sure about STRUCT, but I assume that would be screened at QA. Thanks...
( from lib/python3.8/site-packages/google/cloud/bigquery/schema.py )
def to_api_repr(self) -> dict:
"""Return a dictionary representing this schema field.