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

refactor AccessEntry to use _properties pattern #1077

Closed
tswast opened this issue Dec 1, 2021 · 2 comments · Fixed by #1125
Closed

refactor AccessEntry to use _properties pattern #1077

tswast opened this issue Dec 1, 2021 · 2 comments · Fixed by #1125
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. type: process A process-related concern. May include testing, release, or the like.

Comments

@tswast
Copy link
Contributor

tswast commented Dec 1, 2021

Is your feature request related to a problem? Please describe.

Often there is a private preview feature (or just a new feature that we haven't implemented yet) and we want to provide our customers a workaround to be able to send a resource as represented by JSON. Then we could have provided a workaround to the user in #1064 like the following:

entry = AccessEntry.from_api_repr({
  "role": "READER",
  "dataset": {
    "projectId": "project-id",
    "datasetId": "dataset_id",
  }
})

or even

entry = AccessEntry("READER")
entry._properties["dataset"] = {
    "projectId": "project-id",
    "datasetId": "dataset_id",
}

and been confident that it would send the correct values when making the API request.

Likewise, one could read values from the API like entry._properties["dataset"] when checking values from the API.

Describe the solution you'd like

The way we handle entity_type and entity_id is reminiscent of ExternalConfig.options, which I refactored in #994. It was clever at the time when there were only a few external data formats, but has diverged far the actual API representation.

AccessEntry should have separate properties for view, routine, dataset, etc. These could accept and return relevant types (e.g. TableReference) as well.

Existing entity_type and entity_id should be made optional in the constructor, but in the same order so that backwards compatibility is maintained.

Describe alternatives you've considered

Leaving the class as-is should continue to work, but it's a significant risk IMO.

Additional context

As identified in #1075

See similar work in #994

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Dec 1, 2021
@tswast tswast added the type: process A process-related concern. May include testing, release, or the like. label Dec 1, 2021
@tswast
Copy link
Contributor Author

tswast commented Dec 1, 2021

Eventually, I'd like to see to_api_repr become return copy.deepcopy(self._properties) as we have in our other resource objects, but I proposed a stepping stone in #1075 where we start to_api_repr with resource = copy.deepcopy(self._properties) here:

resource = {self._entity_type: self._entity_id}

@tswast
Copy link
Contributor Author

tswast commented Dec 13, 2021

Assigning to @steffnay , as I believe she's already done some work on this through #1075

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. type: process A process-related concern. May include testing, release, or the like.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants