TypeError: Unsupported operand types: string + int in Drupal\smart_date\Plugin\migrate\process\ParseDates->transform()

Created on 25 April 2024, 5 months ago
Updated 29 April 2024, 5 months ago

Problem/Motivation

Running the drush mim command while using the parse_dates process plugin that was introduced https://www.drupal.org/project/smart_date/issues/3060042 ✨ Provide migrate support to upgrade from Date module on D7 Needs review resulted in the following error.

TypeError: Unsupported operand types: string + int in Drupal\smart_date\Plugin\migrate\process\ParseDates->transform() (line 329.

The D7 field I was trying to migrate was the D7 core date field.

The YAML structure was identical to the code example on top of the class.

Could this be resolved with a simple type cast?

Drupal: 10.2.5

πŸ› Bug report
Status

Needs review

Version

4.1

Component

Code

Created by

πŸ‡¬πŸ‡·Greece Pavlos.Dontas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Pavlos.Dontas
  • First commit to issue fork.
  • Merge request !113Cast `$k` to an integer β†’ (Open) created by mandclu
  • Status changed to Needs review 5 months ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Casting the $k is definitely a good place to start. It does seem like the code is expecting numeric keys but your data has some strings, so it's possible other issues will arise, but it's worth a try.

  • πŸ‡¬πŸ‡·Greece Pavlos.Dontas

    It turns out that it was a mistake on my part. The problem was in the way I was accessing the D7 date field in the migration yaml.

    I was doing source: field_date instead of source: field_date/0/value. I found this out after adding the type casting changes and re-trying to update migration.

    The error msg was SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_smart_date_end_value' cannot be null, and so it became clear that field data was not correct.

    Sorry for the inconvenience, I believe the status can be set to "closed works as intended"?

  • Status changed to Closed: works as designed 5 months ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Great, thanks for the follow-up. Is this something that should be documented?

  • First commit to issue fork.
  • Pipeline finished with Success
    5 months ago
    #159993
  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States apkwilson

    I've run into this same issue with a D7 date_repeat field, including getting the follow-up error 'field_smart_date_end_value' cannot be null. While trying to handle that, I came to a different conclusion.

    The migration plugin is written to handle all the field values for the migrating row at once, but the migration system was passing values one by one. That meant that, rather than being a field deltas, $k was value, value2, or rrule. After casting $k as (int), the key the plugin was trying to access for the end value wasn't present - it was that very key that had been casted.

    The solution in MR!117 was adding the migration plugin annotation handle_multiples, which tells the migration system to pass in all the row's field values at once. That's the input the plugin expects, and it resolved all the errors I encountered. All the instances of my repeating dates were created correctly.

    Any UNTIL date of the rrule isn't being converted from D7 date format, but that's a separate issue.

  • Pipeline finished with Success
    5 months ago
    #160043
  • πŸ‡¨πŸ‡¦Canada mandclu

    Interesting! It does seem like this does indeed align with how the class was written, and it seems like a "low risk" solution, but I would love to get some additional community feedback on this one before we commit the change.

Production build 0.71.5 2024