File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Filter options
google/cloud/bigquery/job Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Original file line number Diff line number Diff line change @@ -659,6 +659,14 @@ def __init__(self, job_type, **kwargs):
659
659
for prop , val in kwargs .items ():
660
660
setattr (self , prop , val )
661
661
662
+ def __setattr__ (self , name , value ):
663
+ """Override to be able to raise error if an unknown property is being set"""
664
+ if not name .startswith ("_" ) and not hasattr (type (self ), name ):
665
+ raise AttributeError (
666
+ "Property {} is unknown for {}." .format (name , type (self ))
667
+ )
668
+ super (_JobConfig , self ).__setattr__ (name , value )
669
+
662
670
@property
663
671
def labels (self ):
664
672
"""Dict[str, str]: Labels for the job.
Original file line number Diff line number Diff line change 76
76
from google .cloud .bigquery .dataset import DatasetReference
77
77
from google .cloud .bigquery .table import Table
78
78
from google .cloud ._helpers import UTC
79
- from google .cloud .bigquery import dbapi
79
+ from google .cloud .bigquery import dbapi , enums
80
80
from google .cloud import storage
81
81
82
82
from test_utils .retry import RetryErrors
@@ -1789,10 +1789,8 @@ def test_query_w_wrong_config(self):
1789
1789
rows = list (Config .CLIENT .query ("SELECT 1;" ).result ())
1790
1790
assert rows [0 ][0 ] == 1
1791
1791
1792
- project = Config .CLIENT .project
1793
- dataset_ref = bigquery .DatasetReference (project , "dset" )
1794
1792
bad_config = LoadJobConfig ()
1795
- bad_config .destination = dataset_ref . table ( "tbl" )
1793
+ bad_config .source_format = enums . SourceFormat . CSV
1796
1794
with self .assertRaises (Exception ):
1797
1795
Config .CLIENT .query (good_query , job_config = bad_config ).result ()
1798
1796
Original file line number Diff line number Diff line change 19
19
from google .api_core import exceptions
20
20
import google .api_core .retry
21
21
import mock
22
+ import pytest
22
23
23
24
from .helpers import _make_client
24
25
from .helpers import _make_connection
@@ -1021,6 +1022,12 @@ def test_ctor(self):
1021
1022
self .assertEqual (job_config ._job_type , self .JOB_TYPE )
1022
1023
self .assertEqual (job_config ._properties , {self .JOB_TYPE : {}})
1023
1024
1025
+ def test_ctor_with_unknown_property_raises_error (self ):
1026
+ error_text = "Property wrong_name is unknown for"
1027
+ with pytest .raises (AttributeError , match = error_text ):
1028
+ config = self ._make_one ()
1029
+ config .wrong_name = None
1030
+
1024
1031
def test_fill_from_default (self ):
1025
1032
from google .cloud .bigquery import QueryJobConfig
1026
1033
You can’t perform that action at this time.
0 commit comments