Implement generic `stripKnownOptions` to restore strict validation (Breaking Change)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Start by tracing how Database.php uses ArrayTrait::pluckArray() before options reach Operation.php, then read OptionsValidator::validateOptions() to understand the existing strict validation. Confirm which Spanner-level keys Database.php consumes and verify that remaining valid options pass through while unknown keys reach Operation.php and raise LogicException as intended.
Written by the indexing model from the issue text.
Description
Currently, Spanner\Database and Spanner\Transaction use ArrayTrait::pluckArray() to extract a hardcoded whitelist of options before passing the remainder of the request to the Operation layer.
The Problem:
Using pluckArray() as a hardcoded whitelist has two major flaws:
- It silently drops valid options: Every time a new GAX call option or Spanner configuration is added, it must be manually added to the
pluckArray. If forgotten, valid options (liketimeoutMillis) are silently dropped, causing bugs. #9378 is planned to patch the valid options that are being dropped. - It defeats strict validation: The original goal of
OptionsValidator::validateOptions()in theOperationlayer is to catch typos and undocumented keys by throwing aLogicException. BecausepluckArray()at theDatabaselevel silently drops unknown keys, theOptionsValidatornever receives the typo'd keys and cannot throw the intended exception.
Proposed Solution:
Instead of relying on hardcoded whitelists (pluckArray) inDatabase.php, we should implement a generic method (e.g.,stripKnownOptions) in the globalOptionsValidator(or simply use explicitunset()statements).
This allows higher-level classes like Database to explicitly strip only the specific Spanner-level keys they consume (e.g., begin, transactionType, sessionOptions). They can then safely pass the entire remaining array down to Operation.php.
Expected Outcome:
- Valid GAX/Protobuf options will safely pass down to
Operation.phpwithout needing to be hardcoded inDatabase.php. - Unknown, undocumented, or typo'd options will also pass down to
Operation.php, where they will correctly trigger the strictvalidateOptions()check and throw an exception.
🚨 Breaking Change Notice 🚨
This is a breaking change and must be slated for a major version update. By removing the silent dropping of unknown keys in Database.php, we are restoring strict validation. Any users who are currently passing undocumented or typo'd keys (which were previously silently ignored) will begin encountering LogicExceptions upon upgrading.
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 464
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 103
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-cloud-php
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
googleapis/google-cloud-php#9730 ·
-
type: feature request
Difficulty 1/5 Under an hour Newbie friendliness 75/100
googleapis/google-cloud-php#9716 · 11 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
googleapis/google-cloud-php#9725 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
googleapis/google-cloud-php#9675 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
googleapis/google-cloud-php#9674 · 1 comment ·
All issues in googleapis/google-cloud-php
Similar issues
-
tooling
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
UX
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
OpenConext/OpenConext-engineblock#2122 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/safe-publish#594 ·