Problem/Motivation

After updating from 8.x-1.9 to 8.x-1.11 (and updating commerce-guys/addressing) the following error is logged every time we try indexing content that has an address field:

[error] TypeError: CommerceGuys\Addressing\Locale::match(): Argument #2 ($secondLocale) must be of type string, null given, called in /var/www/html/web/modules/contrib/address/src/TypedData/SubdivisionName.php on line 132 in CommerceGuys\Addressing\Locale::match() (line 241 of /var/www/html/vendor/commerceguys/addressing/src/Locale.php) #0 /var/www/html/web/modules/contrib/address/src/TypedData/SubdivisionName.php(132): CommerceGuys\Addressing\Locale::match('en', NULL)
#1 /var/www/html/web/modules/contrib/address/src/TypedData/SubdivisionName.php(68): Drupal\address\TypedData\SubdivisionName->resolveAddressName('administrative_...', Object(Drupal\address\Plugin\Field\FieldType\AddressItem))
#2 /var/www/html/web/modules/contrib/search_api/src/Utility/FieldsHelper.php(210): Drupal\address\TypedData\SubdivisionName->getValue()
#3 /var/www/html/web/modules/contrib/search_api/src/Utility/FieldsHelper.php(176): Drupal\search_api\Utility\FieldsHelper->extractFieldValues(Object(Drupal\address\TypedData\SubdivisionName))
#4 /var/www/html/web/modules/contrib/search_api/src/Utility/FieldsHelper.php(144): Drupal\search_api\Utility\FieldsHelper->extractField(Object(Drupal\address\TypedData\SubdivisionName), Object(Drupal\search_api\Item\Field))
#5 /var/www/html/web/modules/contrib/search_api/src/Utility/FieldsHelper.php(165): Drupal\search_api\Utility\FieldsHelper->extractFields(Object(Drupal\address\Plugin\Field\FieldType\AddressItem), Array, 'en')
#6 /var/www/html/web/modules/contrib/search_api/src/Item/Item.php(276): Drupal\search_api\Utility\FieldsHelper->extractFields(Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter), Array, 'en')
#7 /var/www/html/web/modules/contrib/search_api/src/Plugin/search_api/processor/RenderedItem.php(256): Drupal\search_api\Item\Item->getFields()
#8 /var/www/html/web/modules/contrib/search_api/src/Item/Item.php(282): Drupal\search_api\Plugin\search_api\processor\RenderedItem->addFieldValues(Object(Drupal\search_api\Item\Item))
#9 /var/www/html/web/modules/contrib/search_api/src/Entity/Index.php(976): Drupal\search_api\Item\Item->getFields()
#10 /var/www/html/web/modules/contrib/search_api/src/Entity/Index.php(930): Drupal\search_api\Entity\Index->indexSpecificItems(Array)
#11 /var/www/html/web/modules/contrib/search_api/src/IndexBatchHelper.php(154): Drupal\search_api\Entity\Index->indexItems(50)
#12 /var/www/html/vendor/drush/drush/includes/batch.inc(256): Drupal\search_api\IndexBatchHelper::process(Object(Drupal\search_api\Entity\Index), 50, 6327, Object(DrushBatchContext))
#13 /var/www/html/vendor/drush/drush/includes/batch.inc(201): _drush_batch_worker()
#14 /var/www/html/vendor/drush/drush/includes/batch.inc(95): _drush_batch_command('3')
#15 /var/www/html/vendor/drush/drush/src/Drupal/Commands/core/BatchCommands.php(20): drush_batch_command('3')
#16 [internal function]: Drush\Drupal\Commands\core\BatchCommands->process('3', Array)
#17 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#18 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#19 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#20 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#21 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/html/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /var/www/html/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#28 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#29 /var/www/html/vendor/bin/drush(120): include('/var/www/html/v...')
#30 {main}.

Prior to updating the content would index correctly.

Steps to reproduce

* Add a location field to a content type.
* Add the location field to the search_api index's fields configuration.
* Try indexing the content.

Proposed resolution

Fix the bug.

Remaining tasks

Fix the bug.

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

Issue summary: View changes
damienmckenna’s picture

The $parent object has this data:

[langcode] => 
[country_code] => US
[administrative_area] => TX
[locality] => Plano
[dependent_locality] => ''
[postal_code] => 75093
[sorting_code] => ''
[address_line1] => 1540 West Thingy Road
[address_line2] => Suite 100
[organization] => Organization name
[given_name] => ''
[additional_name] => ''
[family_name] => ''

(some values changed for demo purposes)

By the time it gets to the $subdivision logic $property_value is set to 'TX' and $address_parent_values is set to array('US'). The problem is that CommerceGuys\Addressing\Subdivision\Subdivision::getLocale() can return a NULL if there is no locale defined for that subdivision, which then results in it passing a NULL into Locale::match(), which causes the failure.

damienmckenna’s picture

Status: Active » Closed (duplicate)
Parent issue: » #2812659: Integrate Address with Search API

This is actually a bug in the patch from #2812659.