SFDO-Tooling / CumulusCI

Python framework for building portable automation for Salesforce projects
http://cumulusci.readthedocs.io
BSD 3-Clause "New" or "Revised" License
363 stars 242 forks source link

EnsureRecordType task failing with salesforce metadata api error #3826

Closed leo-dcfa closed 2 months ago

leo-dcfa commented 2 months ago

Describe the bug

We use cci to manage multiple customer environments and one of the tasks we have is to ensure a certain record type exists. This task works for 60+ orgs but fails for one of them:

tasks:
    ensure_event_record_type:
        class_path: cumulusci.tasks.salesforce.EnsureRecordTypes
        options:
            record_type_developer_name: Event_Ticket
            record_type_label: Event Ticket
            sobject: Opportunity
            force_create: True

The task works in all orgs except for one, it fails with:

[09/09/24 09:02:36] Org info updated, writing to keychain                                                                                                                                                                                                                                                                                                                                                                        
                    Beginning task: Deploy                                                                                                                                                                                                                                                                                                                                                                                       
                    As user: {ommitted}                                                                                                                                                                                                                                                                                                                                                                             
                    In org: {ommitted}                                                                                                                                                                                                                                                                                                                                                                                   
                    Cleaning meta.xml files of packageVersion elements for deploy                                                                                                                                                                                                                                                                                                                                                
                    Payload size: 896 bytes                                                                                                                                                                                                                                                                                                                                                                                      
                    Pending                                                                                                                                                                                                                                                                                                                                                                                                      
                    [Pending]: next check in 1 seconds                                                                                                                                                                                                                                                                                                                                                                           
[09/09/24 09:02:38] [Done]                                                                                                                                                                                                                                                                                                                                                                                                       
[09/09/24 09:02:39] [Failed]: Update of CustomObject Opportunity: Error on line 7, col 33: Error parsing file: The entity name must immediately follow the '&' in the entity reference.                                                                                                                                                                                                                                          
Error: Could not process MDAPI response: Update of CustomObject Opportunity: Error on line 7, col 33: Error parsing file: The entity name must immediately follow the '&' in the entity reference.
Run this command for more information about debugging errors: cci error --help

Reproduction steps

Run cci task against specific org; otherwise unable to reproduce in other orgs

Your CumulusCI and Python versions

cci: 3.91.0 python version: 3.10.0

Operating System

macOS

Windows environment

No response

CumulusCI installation method

None

Error Gist

https://gist.github.com/leo-dcfa/20e05c1a2981dd04df3b6f64de1db9cc

Additional information

No response

jstvz commented 2 months ago

Thanks for the report, @leo-dcfa. This task isn't sanitizing XML, so I think that's the likely culprit. Does the affected org have a picklist value on StageName that contains an ampersand (&)?

leo-dcfa commented 2 months ago

@jstvz you are right, Identify & Qualify is a value. Seems like an easy fix - I'm happy to tackle it, Python is my most used language. Do we have a preferred way of escaping characters?

jstvz commented 2 months ago

Thanks, @leo-dcfa! You can use xml.sax.saxutils.escape from the stdlib. For example, see:

https://github.com/SFDO-Tooling/CumulusCI/blob/da6044613abb1b48d91aacc6e8bc47bd3de64fb4/cumulusci/salesforce_api/metadata.py#L656-L661

leo-dcfa commented 2 months ago

@jstvz https://github.com/SFDO-Tooling/CumulusCI/pull/3827/files there you go

jstvz commented 2 months ago

Fixed by #3827