- Issue created by @chandu7929
- Merge request !152Update method signature with appropriate changes. โ (Open) created by chandu7929
- ๐บ๐ธUnited States japerry KVUO
I'm going to need more detail here. The existing parameter 'version_id' is already optional, so it should not be throwing an error. Is there a backtrace showing where omission of the version_id parameter within getAsset is throwing an error vs using NULL?
- ๐ฎ๐ณIndia chandu7929 Pune
Hello @Japerry,
The optional parameter should be set to null rather than an empty stringโunless there's a specific reason to use an empty string in the method. Using an empty string can cause an error when the function is called without the second parameter, as it expects a value of type string. This results in the following error:
"Argument #2 ($version_id) must be of type string",
which is inaccurate in this context.
Please refer to the error trace from the getAsset() call in media_acquiadam where version_id is not passed.
[error] Client error: `GET https://api.widencollective.com/v2/assets/0c772875-c010-47af-bf7e-2a2080587d50/versions?expand=asset_properties,embeds,file_properties,metadata,metadata_info,metadata_vocabulary,security,thumbnails` resulted in a `404 Not Found` response: > { > "error": true, > "response_code": 404, > "error_message": "Asset with UUID 0c772875-c010-47af-bf7e-2a2080587d50 not (truncated...) > [error] TypeError: Drupal\acquia_dam\Client\AcquiaDamClient::getAsset(): Argument #2 ($version_id) must be of type string, null given, called in /var/www/html/web/modules/contrib/acquia_dam/src/Plugin/media/Source/Asset.php on line 234 in Drupal\acquia_dam\Client\AcquiaDamClient->getAsset() (line 170 of /var/www/html/web/modules/contrib/acquia_dam/src/Client/AcquiaDamClient.php) #0 /var/www/html/web/modules/contrib/acquia_dam/src/Plugin/media/Source/Asset.php(234): Drupal\acquia_dam\Client\AcquiaDamClient->getAsset()
- ๐บ๐ธUnited States japerry KVUO
No, the problem is that
$asset = $this->clientFactory->getSiteClient()->getAsset($asset_id, $version_id);
is passing an NULL, which it shouldn't be doing -- but it appears thatpublic function getFinalizedVersion(string $asset_id): ?string {
is returning NULL or string, which it shouldn't be doing -- it should always return a string.However, changing that response from NULL|String could cause other issues, so the easiest fix is just change line Asset.php:234 to check null coalesce
$asset = $this->clientFactory->getSiteClient()->getAsset($asset_id, $version_id ?? '');
- ๐ฎ๐ณIndia chandu7929 Pune
Passing a blank string serves as a workaround to bypass the error. Ideally, we should update the method signature to accept null as an optional parameter. However, it's unclear what the implications of passing null might be, although all tests are currently passing with this change.
- ๐บ๐ธUnited States japerry KVUO
After discussion with mglaman, the original cause of this is fixed in #3524222. Any change to the signature here is a bandaid over the underlying issue, which is $version_id, if set, should actually be a string and not null.