fix(bigframes): resolve session-scoped API method logging - #18076
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the session resolution logic in log_adapter.py to search through all positional arguments for a Session instance or objects containing a _session or session attribute. It also updates the unit tests in test_io_bigquery.py to use explicit mock sessions and log adapter calls instead of relying on DataFrame operations. The review feedback suggests refactoring the session attribute lookup in _find_session to eliminate duplicated code by iterating over a tuple of attribute names.
0f0d41f to
74e2ba2
Compare
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| for arg in args: | ||
| if isinstance(arg, Session) and _is_session_initialized(arg): | ||
| return arg | ||
| if hasattr(arg, "__dict__") and "_block" in arg.__dict__: | ||
| session = getattr(arg, "_session", None) | ||
| if isinstance(session, Session) and _is_session_initialized(session): | ||
| return session | ||
|
|
There was a problem hiding this comment.
Should be place this before the kwargs check to preserve the original checking sequence?
There was a problem hiding this comment.
Good point! Reordered _find_session to check args before kwargs, preserving the original sequence.
🤖 I have created a release *beep* *boop* --- ## [2.48.0](bigframes-v2.47.0...bigframes-v2.48.0) (2026-08-12) ### Features * **bigframes:** Transpiler supports more string ops ([#17693](#17693)) ([7d2bc21](7d2bc21)) ### Bug Fixes * **bigframes:** fix field name typos for ai.generate* functions ([#17983](#17983)) ([1b5c48b](1b5c48b)) * **bigframes:** resolve session-scoped API method logging ([#18076](#18076)) ([ace618b](ace618b)) * **bigframes:** update GeminiTextGenerator default model to gemini-2.5-flash ([#18060](#18060)) ([5770ff6](5770ff6)) * bump @angular/compiler, @angular/common, @angular/core, @angular/forms, @angular/platform-browser, @angular/router and @angular/compiler-cli in /packages/bigframes/bigframes/display/table_widget_angular ([#17992](#17992)) ([346aaab](346aaab)) * bump fast-uri from 3.1.4 to 3.1.5 in /packages/bigframes/bigframes/display/table_widget_angular ([#17989](#17989)) ([3b3f3f4](3b3f3f4)) * bump hono from 4.12.31 to 4.13.1 in /packages/bigframes/bigframes/display/table_widget_angular ([#18032](#18032)) ([cddf35b](cddf35b)) * bump ip-address and express-rate-limit in /packages/bigframes/bigframes/display/table_widget_angular ([#17985](#17985)) ([02ed656](02ed656)) * bump undici and @angular/build in /packages/bigframes/bigframes/display/table_widget_angular ([#17986](#17986)) ([6938061](6938061)) * bump undici from 7.25.0 to 7.29.0 in /packages/bigframes/tests/js ([#17987](#17987)) ([65a3571](65a3571)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
🤖 I have created a release *beep* *boop* --- ## [2.48.0](googleapis/google-cloud-python@bigframes-v2.47.0...bigframes-v2.48.0) (2026-08-12) ### Features * **bigframes:** Transpiler supports more string ops ([#17693](googleapis/google-cloud-python#17693)) ([7d2bc21](googleapis/google-cloud-python@7d2bc21)) ### Bug Fixes * **bigframes:** fix field name typos for ai.generate* functions ([#17983](googleapis/google-cloud-python#17983)) ([1b5c48b](googleapis/google-cloud-python@1b5c48b)) * **bigframes:** resolve session-scoped API method logging ([#18076](googleapis/google-cloud-python#18076)) ([ace618b](googleapis/google-cloud-python@ace618b)) * **bigframes:** update GeminiTextGenerator default model to gemini-2.5-flash ([#18060](googleapis/google-cloud-python#18060)) ([5770ff6](googleapis/google-cloud-python@5770ff6)) * bump @angular/compiler, @angular/common, @angular/core, @angular/forms, @angular/platform-browser, @angular/router and @angular/compiler-cli in /packages/bigframes/bigframes/display/table_widget_angular ([#17992](googleapis/google-cloud-python#17992)) ([346aaab](googleapis/google-cloud-python@346aaab)) * bump fast-uri from 3.1.4 to 3.1.5 in /packages/bigframes/bigframes/display/table_widget_angular ([#17989](googleapis/google-cloud-python#17989)) ([3b3f3f4](googleapis/google-cloud-python@3b3f3f4)) * bump hono from 4.12.31 to 4.13.1 in /packages/bigframes/bigframes/display/table_widget_angular ([#18032](googleapis/google-cloud-python#18032)) ([cddf35b](googleapis/google-cloud-python@cddf35b)) * bump ip-address and express-rate-limit in /packages/bigframes/bigframes/display/table_widget_angular ([#17985](googleapis/google-cloud-python#17985)) ([02ed656](googleapis/google-cloud-python@02ed656)) * bump undici and @angular/build in /packages/bigframes/bigframes/display/table_widget_angular ([#17986](googleapis/google-cloud-python#17986)) ([6938061](googleapis/google-cloud-python@6938061)) * bump undici from 7.25.0 to 7.29.0 in /packages/bigframes/tests/js ([#17987](googleapis/google-cloud-python#17987)) ([65a3571](googleapis/google-cloud-python@65a3571)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> GitOrigin-RevId: 102c940183ac1cf5670b46c17a47f559926634de Change-Id: Ia15429511df3ebed77f5b4ad45779f8c6be0316d
Fixes an issue where API method calls on DataFrame and Series objects were recorded into global state instead of their specific session, preventing cross-session and cross-test logging interference. - Updated `log_adapter._find_session` to detect active sessions directly from DataFrame and Series instances. - Added recursion safeguards during session property lookup in `log_adapter`. Fixes #<545233537> 🦕 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
🤖 I have created a release *beep* *boop* --- ## [2.48.0](bigframes-v2.47.0...bigframes-v2.48.0) (2026-08-12) ### Features * **bigframes:** Transpiler supports more string ops ([#17693](#17693)) ([7d2bc21](7d2bc21)) ### Bug Fixes * **bigframes:** fix field name typos for ai.generate* functions ([#17983](#17983)) ([1b5c48b](1b5c48b)) * **bigframes:** resolve session-scoped API method logging ([#18076](#18076)) ([ace618b](ace618b)) * **bigframes:** update GeminiTextGenerator default model to gemini-2.5-flash ([#18060](#18060)) ([5770ff6](5770ff6)) * bump @angular/compiler, @angular/common, @angular/core, @angular/forms, @angular/platform-browser, @angular/router and @angular/compiler-cli in /packages/bigframes/bigframes/display/table_widget_angular ([#17992](#17992)) ([346aaab](346aaab)) * bump fast-uri from 3.1.4 to 3.1.5 in /packages/bigframes/bigframes/display/table_widget_angular ([#17989](#17989)) ([3b3f3f4](3b3f3f4)) * bump hono from 4.12.31 to 4.13.1 in /packages/bigframes/bigframes/display/table_widget_angular ([#18032](#18032)) ([cddf35b](cddf35b)) * bump ip-address and express-rate-limit in /packages/bigframes/bigframes/display/table_widget_angular ([#17985](#17985)) ([02ed656](02ed656)) * bump undici and @angular/build in /packages/bigframes/bigframes/display/table_widget_angular ([#17986](#17986)) ([6938061](6938061)) * bump undici from 7.25.0 to 7.29.0 in /packages/bigframes/tests/js ([#17987](#17987)) ([65a3571](65a3571)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Fixes an issue where API method calls on DataFrame and Series objects were recorded into global state instead of their specific session, preventing cross-session and cross-test logging interference.
log_adapter._find_sessionto detect active sessions directly from DataFrame and Series instances.log_adapter.Fixes #<545233537> 🦕