Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Some kind of new issue with country codes #69

@adrienne

Description

@adrienne

As far as i can tell, all my addresses have country codes, but suddenly i'm getting the following nasty error (and Calendar, where the field is, won't display any events):

2021-12-15 22:16:37 [-][1][ba831e37695d94ceda352effa9e007d3][error][InvalidArgumentException] InvalidArgumentException: Missing required property country_code. in /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/commerceguys/addressing/src/AddressFormat/AddressFormat.php:125
Stack trace:
#0 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/commerceguys/addressing/src/AddressFormat/AddressFormatRepository.php(24): CommerceGuys\Addressing\AddressFormat\AddressFormat->__construct(Array)
#1 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/commerceguys/addressing/src/Formatter/DefaultFormatter.php(79): CommerceGuys\Addressing\AddressFormat\AddressFormatRepository->get('')
#2 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/newism/craft3-fields/src/models/AddressModel.php(69): CommerceGuys\Addressing\Formatter\DefaultFormatter->format(Object(newism\fields\models\AddressModel))
#3 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/newism/craft3-fields/src/fields/Address.php(151): newism\fields\models\AddressModel->__toString()
#4 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/base/Element.php(3895): newism\fields\fields\Address->getTableAttributeHtml(Object(newism\fields\models\AddressModel), Object(Solspace\Calendar\Elements\Event))
#5 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/solspace/craft3-calendar/packages/plugin/src/Elements/Event.php(1363): craft\base\Element->tableAttributeHtml('field:113')
#6 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/base/Element.php(3771): Solspace\Calendar\Elements\Event->tableAttributeHtml('field:113')
#7 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Extension/CoreExtension.php(1511): craft\base\Element->getTableAttributeHtml('field:113')
#8 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/helpers/Template.php(106): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(Solspace\Calendar\Elements\Event), 'getTableAttribu...', Array, 'method', false, false)
#9 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/storage/runtime/compiled_templates/2f/2f7c2ee693d2d57be8ce369801643692d2f0905af626615a4b35888cda337505.php(167): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(Solspace\Calendar\Elements\Event), 'getTableAttribu...', Array, 'method')
#10 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Template.php(405): __TwigTemplate_a68a8d7cfebcad52f622e21ffaf0fa3bec9ebf8cb08005427fc4b799af56c123->doDisplay(Array, Array)
#11 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#12 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/storage/runtime/compiled_templates/70/70f6ee75d08c5c2e114a7386fc422c64a2addb5ea85f333d77b9a7f748992007.php(102): Twig\Template->display(Array)
#13 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Template.php(405): __TwigTemplate_777d67033b187bb833676d73c70f5ee0c4c6951ad1dea2d78183f389df228f19->doDisplay(Array, Array)
#14 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#15 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#16 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#17 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#18 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/web/View.php(408): Twig\Environment->render('_elements/table...', Array)
#19 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/base/Element.php(871): craft\web\View->renderTemplate('_elements/table...', Array)
#20 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/controllers/ElementIndexesController.php(534): craft\base\Element::indexHtml(Object(Solspace\Calendar\Elements\Db\EventQuery), Array, Array, '*', 'index', true, true)
#21 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/controllers/ElementIndexesController.php(135): craft\controllers\ElementIndexesController->elementResponseData(true, true)
#22 [internal function]: craft\controllers\ElementIndexesController->actionGetElements()
#23 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#24 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#25 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('get-elements', Array)
#26 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/web/Application.php(287): yii\base\Module->runAction('element-indexes...', Array)
#27 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/web/Application.php(596): craft\web\Application->runAction('element-indexes...', Array)
#28 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/craftcms/cms/src/web/Application.php(266): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#29 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /chroot/home/a5ebbf88/4f9443c764.nxcli.net/html/index.php(21): yii\base\Application->run()
#31 {main}
2021-12-15 22:16:36 [-][1][ba831e37695d94ceda352effa9e007d3][info][application] Request body: {"context":"index","elementType":"Solspace\\Calendar\\Elements\\Event","source":"*","criteria":{"siteId":4,"search":null,"offset":0,"limit":100,"status":null},"disabledElementIds":[],"viewState":{"mode":"table","order":"title","sort":"asc"},"paginated":1}

I've temporarily patched this by changing line 218 of src/models/AddressModel.php from:

 return $this->countryCode;

to:

 return $this->countryCode ?? 'US';

but obviously that's a patch, not a real solution.

The field does have a default countryCode set, and as I say, all my addresses do in fact have a countryCode in the JSON as well.

There is an empty country key that I don't remember seeing before, however. Did something change recently?

Here's an actual example of JSON from my field (i've pretty-printed it but nothing else):

{
	"country": {},
	"placeData": {
		"address_components": [{
			"long_name": "157",
			"short_name": "157",
			"types": ["street_number"]
		}, {
			"long_name": "Orange Street",
			"short_name": "Orange St",
			"types": ["route"]
		}, {
			"long_name": "Downtown",
			"short_name": "Downtown",
			"types": ["neighborhood", "political"]
		}, {
			"long_name": "New Haven",
			"short_name": "New Haven",
			"types": ["locality", "political"]
		}, {
			"long_name": "New Haven County",
			"short_name": "New Haven County",
			"types": ["administrative_area_level_2", "political"]
		}, {
			"long_name": "Connecticut",
			"short_name": "CT",
			"types": ["administrative_area_level_1", "political"]
		}, {
			"long_name": "United States",
			"short_name": "US",
			"types": ["country", "political"]
		}, {
			"long_name": "06510",
			"short_name": "06510",
			"types": ["postal_code"]
		}, {
			"long_name": "3111",
			"short_name": "3111",
			"types": ["postal_code_suffix"]
		}],
		"formatted_address": "157 Orange St, New Haven, CT 06510, USA",
		"geometry": {
			"location": {
				"lat": 41.306002599999999,
				"lng": -72.923596099999997
			},
			"viewport": {
				"south": 41.3046828697085,
				"west": -72.925072780291515,
				"north": 41.3073808302915,
				"east": -72.922374819708494
			}
		},
		"name": "157 Orange St",
		"place_id": "ChIJlzRaS7XZ54kRfohanvaBA6A",
		"url": "https:\/\/maps.google.com\/?q=157+Orange+St,+New+Haven,+CT+06510,+USA&ftid=0x89e7d9b54b5a3497:0xa00381f69e5a887e",
		"html_attributions": []
	},
	"latitude": 41.306002599999999,
	"longitude": -72.923596099999997,
	"mapUrl": "https:\/\/maps.google.com\/?q=157+Orange+St,+New+Haven,+CT+06510,+USA&ftid=0x89e7d9b54b5a3497:0xa00381f69e5a887e",
	"countryCode": "US",
	"administrativeArea": "CT",
	"locality": "New Haven",
	"dependentLocality": null,
	"postalCode": "06510",
	"sortingCode": null,
	"addressLine1": "157 Orange St",
	"addressLine2": null,
	"organization": null,
	"recipient": null,
	"givenName": null,
	"additionalName": null,
	"familyName": null,
	"locale": null
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions