Problem/Motivation

If the AddressFormatConstraintValidator can't find a subfield label for a given violation, it will not set a value at all. This can lead to fatal errors in some cases.

Steps to reproduce

Proposed resolution

In AddressFormatConstraintValidator, if a label is not defined, fallback to using the field label in the message.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
feeds.feed_type.property_import.yml3.24 KBmalcomio

Issue fork address-3550247

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

malcomio created an issue. See original summary.

malcomio’s picture

This error comes from the address module's AddressFormatConstraint, so possibly that module is the source of the error?

malcomio’s picture

Title: TypeError from Html::escape() when rendering import errors » AddressFormatConstraintValidator does not always set field names correctly
Project: Feeds » Address
Version: 8.x-3.0 » 2.0.4

Having debugged further, the problem is that AddressFormatConstraintValidator does not always

In my case the administrativeArea and dependentLocality field have no labels, so the violation doesn't specify them properly.

malcomio’s picture

Status: Active » Needs review
cspitzlay’s picture

A customer of ours triggered this crash yesterday, too.

I think this happens when working with non-empty address fields for country codes that do not have them as part of their country-specific format / do not specify a type for it. In my customer's case that's country code 'IT' and the dependent_locality field.

I guess it is not possible to create this situation via the standard Commerce UI because it will automatically remove any fields that do not make sense for the selected country. But programmatically this case is possible.

I think that before PHP 8.4 or and/or with a previous version of the module this issue was silently ignored because PHP would happily convert the value NULL into an empty string which resulted in a non-helpful error message, but no crash.

cspitzlay’s picture

Status: Needs review » Reviewed & tested by the community

I looked at the suggested change and tested it. It fixes the issue for me. It cannot provide a label out of thin air, of course, but at least it prevents the type error and the resulting error message, e.g. 'dependentLocality field must be blank.' is helpful for the developer who reads it. In the UI this case should not happen in the first place.

malcomio’s picture

I think when we saw this it was on PHP 8.3

cspitzlay’s picture

I definitely recall seeing the message without a field name, i.e. at the time it did not crash.
But I am not sure what combination of PHP and module versions we had back then.

tbkot made their first commit to this issue’s fork.

dww made their first commit to this issue’s fork.

dww’s picture

Thanks malcomio and cspitzlay for working on this. Normally, I'd both ask for tests, and complain that changes like this tend to mask deeper bugs and make them harder to debug in the future. However, in this case, it's pretty obvious that if there's no label (because we have a value for something outside a country's default address format or whatever) it's better to fall back to the field name than to cause an error without a label at all.

I rebased this against the latest 2.1.x branch and removed commit c64e9809 which was actively harming the ease of reviewing and committing this fix. tBkoT please don't do that again to any other issue. If we're going to do any code style refactoring, it'll be in a separate issue, not as "cleanup while we're at it" in another issue (bug, feature or task). Thanks.

dww’s picture

Title: AddressFormatConstraintValidator does not always set field names correctly » AddressFormatConstraintValidator does not always set a label
Issue summary: View changes

  • dww committed e2f13c22 on 2.1.x authored by malcomio
    fix: #3550247 AddressFormatConstraintValidator does not always set a...

  • dww committed 66d8be6e on 2.0.x authored by malcomio
    fix: #3550247 AddressFormatConstraintValidator does not always set a...
dww’s picture

Status: Reviewed & tested by the community » Fixed

Merged to 2.1.x, cherry picked to 2.0.x and pushed. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.