Skip to content

Conversation

@chalmerlowe
Copy link
Collaborator

@chalmerlowe chalmerlowe commented Sep 12, 2025

🛑 WARNING Github automagically swapped the base branch. This was supposed to merge into the branch in PR #2287 (already merged), but Github changed things which somehow added the _helpers.py.j2 file from #2287 to this PR. That file has already been merged so there is no need to review it. 🛑

The focus of your code review only needs to be these two files:

This PR adds two templates used to generate action methods on the centralized client class (e.g. get_dataset(), list_tables(), delete_routine())

These two templates contemplate two different scenarios where an action method is:

  • expected to be able to accept a string as a path_identifier (e.g. project_id.dataset_id.model_id) > see file: _method_with_request_builder.j2
  • NOT expected to be able to accept a string as a path_identifier > see file: _simple_passthrough_method.j2

The following is an example of what _method_with_request_builder.j2 might be used to generate:

def get_dataset(
    self,
    dataset_id: Optional[str] = None,
    *,
    request: Optional[dataset.GetDatasetRequest] = None,
    retry: OptionalRetry = DEFAULT_RETRY,
    timeout: Union[float, object] = DEFAULT_TIMEOUT,
    metadata: Sequence[Tuple[str, Union[str, bytes]]] = DEFAULT_METADATA,
) -> "dataset.Dataset":
    """
    TODO: Docstring is purposefully blank. microgenerator will add automatically.
    """
    if request and dataset_id is not None:
        raise ValueError("Cannot provide both request and dataset_id.")

    if request:
        final_request = request
    else:
        path_identifier = dataset_id
        if path_identifier is None:
            if len(['project_id', 'dataset_id']) == 1:
                path_identifier = self.project
            else:
                raise ValueError("Either request or dataset_id must be provided.")

        if path_identifier is None:
            raise ValueError("Could not determine a path identifier.")

        request_class = dataset.GetDatasetRequest

        final_request = _helpers._create_request(
            request_class=request_class,
            path_identifier=path_identifier,
            expected_args=['project_id', 'dataset_id'],
            default_project_id=self.project,
        )

    return self.dataset_service_client.get_dataset(
        request=final_request,
        retry=retry,
        timeout=timeout,
        metadata=metadata,
    )

@chalmerlowe chalmerlowe requested review from a team as code owners September 12, 2025 10:53
@chalmerlowe chalmerlowe requested review from leahecole and removed request for a team September 12, 2025 10:53
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Sep 12, 2025
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Sep 12, 2025
@chalmerlowe chalmerlowe added this to the µgen PoC milestone Sep 12, 2025
@chalmerlowe chalmerlowe changed the title feat: adds two partial templates for creating method signatures feat: microgen - adds two partial templates for creating method signatures Sep 15, 2025
@chalmerlowe chalmerlowe mentioned this pull request Sep 15, 2025
1 task
* feat: adds _helpers.py.js  template

* Updates with two usage examples

* updates the license header
Base automatically changed from feat-adds-helpers-template to chore-adds-init-files September 15, 2025 18:00
Migrates the empty __init__.py file to the microgenerator package.
@chalmerlowe chalmerlowe assigned chalmerlowe and unassigned shollyman Sep 16, 2025
@chalmerlowe
Copy link
Collaborator Author

For clarity:

  1. The GitHub Actions are being used to help ensure that unit tests pass.
    Screenshot 2025-08-20 at 9 14 08 AM
  2. The KOKORO tests are failing. This is a known problem and will be dealt with in a separate PR. It should not affect merging into the autogen dev branch.
    Screenshot 2025-08-20 at 9 13 45 AM

Base automatically changed from chore-adds-init-files to autogen September 18, 2025 19:15
@chalmerlowe chalmerlowe merged commit 5a9a4c6 into autogen Sep 18, 2025
14 of 25 checks passed
@chalmerlowe chalmerlowe deleted the feat-adds-method-partials branch September 18, 2025 19:33
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. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants