SFDO-Tooling / CumulusCI

Python framework for building portable automation for Salesforce projects

Home Page:http://cumulusci.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Find And Replace Task Of CumulusCI not working

sahilconcret opened this issue · comments

Describe the bug

I was trying to replace the "%%%CommunityUrl%%%" with the site url via custom task in cumulus with Python Library (FindReplace).
This was the import statement
-> from cumulusci.tasks.util import FindReplace as FindReplace

CumulusCI file task
find_replace_base_community:
description: Replaces a valid card string with the target org's community base URL
class_path: tasks.replace_community_url.FindReplaceCommunityURL
options:
find: "%%%COMMUNITY_BASE_URL%%%"
replace: baseURL
path: unpackaged/config/cmts/customMetadata

Expected behavior:
%%%COMMUNITY_BASE_URL%%% is being replaced by the base URL by a Python task (FindReplaceCommunityURL).
Ex: https://app-energy-9593-dev-ed.scratch.my.site.com/s/payment-router

Actual behavior:
%%%COMMUNITY_BASE_URL%%% is not being replaced by the base URL by a Python task (FindReplaceCommunityURL) instead it is replacing the %%%COMMUNITY_BASE_URL%%% to the string baseURL.
Ex: baseURL/s/payment-router
This error is happening after the cumulus update.
We checked the release notes and there was no update for this task

Reproduction steps

find_replace_base_community:
description: Replaces a valid card string with the target org's community base URL
class_path: tasks.replace_community_url.FindReplaceCommunityURL
options:
find: "%%%COMMUNITY_BASE_URL%%%"
replace: baseURL
path: unpackaged/config/cmts/customMetadata

  1. I ran the above task it was not replacing the destination file with baseUrl which was being setted in Python File instead it was
    replacing it with "baseURL" string only

Your CumulusCI and Python versions

CumulusCI version: 3.75.1 (C:\Users\Sahil Manglani.local\bin\cci)
Python version: 3.9.0 (C:\Users\Sahil Manglani.local\pipx\venvs\cumulusci\Scripts\python.exe)

There is a newer version of CumulusCI available: 3.77.0
To upgrade, run pipx upgrade cumulusci
See the latest CumulusCI Release Notes: https://github.com/SFDO-Tooling/CumulusCI/releases/tag/v3.77.0

Operating System

Windows

Windows environment

Command Prompt

CumulusCI installation method

pipx

Error Gist

No response

Additional information

No response

@sahilconcret This is working as designed. The FindReplace task uses the replace option as a literal replacement. Are you saying that your custom task previously worked as you describe? If so, what was the last version that did so?

@jstvz you are right, but overriding the option values using a custom Python class is not working.
For Example: Created a Python class to replace username names like this.

from cumulusci.tasks.util import FindReplace as FindReplace

class FindReplaceUsername(FindReplace):
    salesforce_task = True # Require a target org
    
    def _init_options(self, kwargs):
        # Run the _init_options logic from FindReplace
        super()._init_options(kwargs)
        # Set the replace option to the org's username
        self.options["replace"] = self.org_config.username

calling this custom task from cumulusci.yml

find_replace_username:
    description: Replaces a string with the target org's username
    class_path: tasks.util.FindReplaceUsername
    options:
            find: "%%%USERNAME%%%"
            replace: userName
            path: unpackaged/config/cmts/customMetadata

This custom implementation is not working in the new release, in the 3.74.0 version it's working fine.

@sahilconcret Please confirm this is an issue you are facing.

@prakash-concret @jstvz Yes this is the issue I am facing and even In 3.75.1 It's working fine.
But versions after that there it is not working as expected.

@prakash-concret Thank you for the reproduction.

Root cause: This is related to a change made to that task as part of #1618 to move to Pydantic-based task option validation framework.

Workaround: The most straightforward workaround is to directly update your task to use parsed_options instead:

diff --git a/tasks/example.py b/tasks/example.py
index f07dc6a..daa2a30 100644
--- a/tasks/example.py
+++ b/tasks/example.py
@@ -50,4 +50,4 @@ class FindReplaceUsername(FindReplace):
         # Run the _init_options logic from FindReplace
         super()._init_options(kwargs)
         # Set the replace option to the org's username
-        self.options["replace"] = self.org_config.username
+        self.parsed_options["replace"] = self.org_config.username

(Not applicable to your use case, but I want to note that some find/replace transforms are available in the deploy task.

Thanks @jstvz @prakash-concret for your help.
In versions later that 3.75.1 we need to use self.parsedoptions instead of self.options.
That works perfectly.