Per #8 Drupal core starting with 10.2 does not require that migrate IDs not include spaces. Since this has never effected migrations except when needing to roll back, we probably don't need to update the minimum Drupal version in the composer file, especially since 10.1 is already EOL.

Revert #3379184: Document that source IDs can only contain alphanumeric characters or underscores

Original description:

In the parent issue, a change was implemented to disallow spaces in source IDs. However, this change was not documented in an explicit change record, and existing migrations which have source IDs containing spaces will break.

There is no documentation regarding exactly how to fix migrations affected by this issue. Can the CSVs continue to use column names with spaces while the migration configuration needs the spaces deleted? Or do both the original CSV and the migrate configuration need to remove spaces?

E.g., would a CSV that has a "Some Column" column name properly map to a "SomeColumn" ID? Or would that not work?

Since this change leads to a minor version upgrade breaking previously-working migrations (a change which maybe should've waited for a major version increment), it's pretty important to get this properly documented.

Additionally, if this update completely prohibits the use of CSVs that includes spaces, it would be preferable to have a code solution to allow spaces in CSV column names and simply remove spaces before mapping columns to source IDs, since updating how CSV headers are exported from a particular source may not be trivial or possible. In these cases manual edits to CSV headers would be needed.

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

caesius created an issue. See original summary.

b2f’s picture

it would be preferable to have a code solution to allow spaces in CSV column names and simply remove spaces before mapping columns to source IDs

Totally agree ! And I don't even understand why there is such a heavy restriction on IDs titles since they are not even stored afaik ? The cell value is stored, not the header label, this requirement needs clarification IMO.

Apparently this comes from a problem in \Drupal\migrate\Plugin\migrate\id_map\Sql::getSourceIdsHash https://www.drupal.org/project/migrate_source_csv/issues/3379184 ...

caesius’s picture

Issue summary: View changes
b2f’s picture

It looks like the only problem is a warning on rollbacks in such case where you have spaces in the header.

[warning] Undefined array key "some CSV header key" Sql.php:232

This warning seems totally non blocking (hence does not justify the constraint in ids) and perhaphs should be tackled in Sql.php ?

b2f’s picture

StatusFileSize
new919 bytes
b2f’s picture

StatusFileSize
new1.25 KB

There you go, as I noticed the warning also is symptom of not actually doing the rollback (only in migrate_map, the actual content is not rollbacked), I patch Sql.php in core to map the values to correct IDs.

https://www.drupal.org/project/drupal/issues/3422603

b2f’s picture

Branch migrate_source_csv-3413894 ready for merge once core is updated (hopefully).

godotislate’s picture

Fix for #3422603: Fixing source IDs with spaces in Sql.php has been committed to 10.2.x-dev, so it should be out in the next 10.2 release. I think this issue then can be converted to be a revert of #3379184: Document that source IDs can only contain alphanumeric characters or underscores and this commit: https://git.drupalcode.org/project/migrate_source_csv/-/commit/91b1488b8...

If it's possible, a test should be added that rolling back with CSV columns containing spaces doesn't emit warnings like [warning] Undefined array key "Some Header with Space" Sql.php:232. I'm not sure whether a core version constraint should be added as well.

godotislate’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Pushed MR with commit to revert. Haven't added the test I mentioned, so leaving at Needs work.

caesius’s picture

Title: No documentation re: fixing source IDs with spaces » Revert requirement that IDs not include spaces
Issue summary: View changes
heddn’s picture

Could we do something less drastic and not remove all the test coverage, but rather adjust it to handle spaces too? Same with the exception?

godotislate’s picture

Could we do something less drastic and not remove all the test coverage, but rather adjust it to handle spaces too? Same with the exception?

There's no longer any restriction on source column names. See https://git.drupalcode.org/project/drupal/-/blob/f45ae4c1201426086212343...

ETA: Not sure the test I mentioned before is actually necessary, since core has test coverage, but it's a nice to have.

godotislate’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Resolved merge conflict and rebased. As mentioned in #13, core has test coverage to make sure spaces and special characters in source names work (see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php?ref_type=heads#L644), so I don't think it's necessary to duplicate here.

Moving to NR.

  • heddn committed 537c9720 on 8.x-3.x authored by godotislate
    Issue #3413894 by b2f, godotislate, heddn: Revert requirement that IDs...
heddn’s picture

Category: Support request » Task
Status: Needs review » Fixed

Thanks for your contributions.

Status: Fixed » Closed (fixed)

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

gaëlg’s picture

Title: Revert requirement that IDs not include spaces » Revert requirement that IDs not include spaces or special characters
m4olivei’s picture

It looks like this was the only change after the 3.7 release. Would love to see a quick tag for this.

heddn’s picture

m4olivei’s picture

AMAZING!

Thanks @heddn. I'm working on a project where patching is a bit of a pain, so this was very helpful!