GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feature: raise error for unknown properties in job config by cguardia · Pull Request #446 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Conversation

@cguardia

@cguardia cguardia commented Dec 22, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Simple feature to raise warning if unknown property is set on job_config instances.

Fixes #303 🦕

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cguardia
feature: warn about unknown properties in job config
995a73f
@cguardia
cguardia requested review from a team and tswast and removed request for a team December 22, 2020 09:51
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Dec 22, 2020
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 22, 2020
tswast
tswast reviewed Jan 7, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/base.py Outdated
def __setattr__(self, name, value):
"""Override to be able to warn if an uknown property is being set"""
if not name.startswith("_") and name not in type(self).__dict__:
warnings.warn("Property {} is unknown for {}.".format(name, type(self)))

@tswast tswast Jan 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

On second thought, I think we can go a step further and throw AttributeError, just like object() instances do.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cguardia cguardia Jan 8, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

OK. Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cguardia
fix: raise error instead of warning
3210f40
@cguardia cguardia changed the title feature: warn about unknown properties in job config feature: raise error for unknown properties in job config Jan 8, 2021
tswast
tswast approved these changes Jan 8, 2021
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tswast

tswast commented Jan 8, 2021

Copy link
Copy Markdown
Contributor
    def __setattr__(self, name, value):
        """Override to be able to raise error if an unknown property is being set"""
        if not name.startswith("_") and name not in type(self).__dict__:
>           raise AttributeError("Property {} is unknown for {}.".format(name, type(self)))
E           AttributeError: Property labels is unknown for <class 'google.cloud.bigquery.job.query.QueryJobConfig'>.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast

tswast commented Jan 8, 2021

Copy link
Copy Markdown
Contributor

It appears you've uncovered a bug in the client. I don't see a setter for labels!

python-bigquery/google/cloud/bigquery/job/base.py

Line 234 in 0337ea0

def labels(self):

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast

tswast commented Jan 8, 2021

Copy link
Copy Markdown
Contributor

Nevermind, there is a setter:

python-bigquery/google/cloud/bigquery/job/base.py

Line 675 in 0337ea0

@labels.setter

Perhaps this logic needs to be adjusted in order to account for properties defined in the superclass?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tswast
tswast suggested changes Jan 8, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/base.py Outdated

def __setattr__(self, name, value):
"""Override to be able to raise error if an unknown property is being set"""
if not name.startswith("_") and name not in type(self).__dict__:

@tswast tswast Jan 8, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Let's try using hasattr to see if that accounts for superclass properties.

Suggested change
if not name.startswith("_") and name not in type(self).__dict__:
if not name.startswith("_") and not hasattr(self, name):

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cguardia cguardia Jan 10, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ok, but we have to use type(self), because if not the properties are looked up on the instance.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cguardia
fix: use hasattr instead of __dict__
d2a8d05
@cguardia
cguardia requested a review from tswast January 12, 2021 19:29
tswast
tswast approved these changes Jan 12, 2021
View reviewed changes
tswast added 3 commits January 12, 2021 16:40
@tswast
Merge branch 'master' into 303-unknown-properties
2fe95b5
@tswast
fix bad merge
f9c0b4c
@tswast
fix system test that sets wrong property
10d6bb6
@tswast

tswast commented Jan 13, 2021

Copy link
Copy Markdown
Contributor

One of our system tests actually had a mistake, which this change caught. There is no "destination" property on LoadJobConfig https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.job.LoadJobConfig.html

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plamut

plamut commented Jan 13, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Re: labels error - as discussed offline, it's actually a bug in the base _AsyncJob.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast
tswast merged commit 1526e39 into googleapis:master Jan 13, 2021
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release python-bigquery 1.27.1 #1097
Closed
evansd added a commit to bennettoxford/openprescribing that referenced this pull request Dec 2, 2022
@evansd
Don't set location attribute on CopyJobConfig
f329a4a
As far as I can tell, this has never been a valid config value here. But
prior to the merging of [this PR][1] in v2.7.0, invalid attributes were
silently ignored.

[1]: googleapis/python-bigquery#446
evansd added a commit to bennettoxford/openprescribing that referenced this pull request Dec 2, 2022
@evansd
Don't set location attribute on CopyJobConfig
23b3476
As far as I can tell, this has never been a valid config value here. But
prior to the merging of [this PR][1] in v2.7.0, invalid attributes were
silently ignored.

[1]: googleapis/python-bigquery#446
@evansd evansd mentioned this pull request Dec 2, 2022
chore(deps): bump google-cloud-bigquery from 1.28.0 to 2.34.4 bennettoxford/openprescribing#3604
Merged
evansd added a commit to bennettoxford/openprescribing that referenced this pull request Dec 2, 2022
@evansd
Don't set location attribute on CopyJobConfig
f3f68cc
As far as I can tell, this has never been a valid config value here. But
prior to the merging of [this PR][1] in v2.7.0, invalid attributes were
silently ignored.

[1]: googleapis/python-bigquery#446
evansd added a commit to bennettoxford/openprescribing that referenced this pull request Dec 2, 2022
@evansd
Don't set location attribute on CopyJobConfig
b0e259b
As far as I can tell, this has never been a valid config value here. But
prior to the merging of [this PR][1] in v2.7.0, invalid attributes were
silently ignored.

[1]: googleapis/python-bigquery#446
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@tswast tswast tswast approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Resource objects such as *JobConfig do not error or warn when setting unknown properties

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@cguardia @tswast @plamut
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.