Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flows are breaking in 0.21.2 for task io.kestra.plugin.scripts.python.Commands #7313

Open
etsiot opened this issue Feb 11, 2025 — with Slack · 12 comments
Open

Flows are breaking in 0.21.2 for task io.kestra.plugin.scripts.python.Commands #7313

etsiot opened this issue Feb 11, 2025 — with Slack · 12 comments
Assignees
Labels
area/backend Needs backend code changes bug Something isn't working

Comments

Copy link

etsiot commented Feb 11, 2025

Long commands are breaking the flows. Example follows:

id: process_document_queue
namespace: paperless.ingest

tasks:
  - id: process_document_queue
    type: io.kestra.plugin.scripts.python.Commands
    description: "Process document queue"
    containerImage: localhost/kestra-python:latest
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker 
      pullPolicy: NEVER
      networkMode: paperless-network
      delete: true
      volumes:
        - "{{ kv('customers', 'paperless') }}:/files/customers"
    warningOnStdErr: false
    namespaceFiles:
      enabled: true
      include:
        - "**"
    commands: 
      - python scripts/process_document_queue.py --amqp_uri "{{kv('rabbitmq','paperless')}}" --paperless_uri "{{ kv('paperless_base_uri','paperless') }}" --paperless_api_token "{{ kv('paperless_api_token','paperless' )}}" --exchange paperless.exchange --document_queue document.pending.queue --document_dlq document.dead.queue --document_routing_key paperless.document --document_dlq_routing_key paperless.dead.document
    timeout: PT3M
triggers:
  - id: consume_document_queue_trigger
    type: io.kestra.plugin.core.trigger.Schedule
    cron: "*/5 * * * * *"
    withSeconds: true

To mitigate I had to break the lines, save the flow and then recombine to one line to be able to execute.
Important to note: lines with breaks are not running either; it appears as though arguments are missing.
If commands:

      - python scripts/process_document_queue.py \
       --amqp_uri "{{kv('rabbitmq','paperless')}}" \
       --paperless_uri "{{ kv('paperless_base_uri','paperless') }}" --paperless_api_token "{{ kv('paperless_api_token','paperless' )}}" --exchange paperless.exchange --document_queue document.pending.queue --document_dlq document.dead.queue --document_routing_key paperless.document --document_dlq_routing_key paperless.dead.document

then i get the error:

025-02-11 21:47:55.746Using task runner 'io.kestra.plugin.scripts.runner.docker.Docker'
2025-02-11 21:47:56.112Container created: f7f8c7418dc4bf5fd120a71f0771a0bd03e5e52eab83b703b7c3879d5f5e18c5
2025-02-11 21:47:56.127Volume created: 608be162dd98040bbe35c8b00d0426b85bd3862e29847d26f112862865fb0ea5
2025-02-11 21:47:56.686Starting command with container id f7f8c7418dc4bf5fd120a71f0771a0bd03e5e52eab83b703b7c3879d5f5e18c5 [/bin/sh -c set -e
python scripts/process_document_queue.py \ --amqp_uri "amqp://guest:xxxxx@rabbitmq:5672/" \ --paperless_uri "http://paperless:8000" --paperless_api_token "xxxxxxxx" --exchange paperless.exchange --document_queue document.pending.queue --document_dlq document.dead.queue --document_routing_key paperless.document --document_dlq_routing_key paperless.dead.document]
2025-02-11 21:47:57.353usage: process_document_queue.py [-h] --amqp_uri AMQP_URI
2025-02-11 21:47:57.356--paperless_uri PAPERLESS_URI
2025-02-11 21:47:57.357--paperless_api_token PAPERLESS_API_TOKEN
2025-02-11 21:47:57.357--exchange EXCHANGE
2025-02-11 21:47:57.357--document_queue DOCUMENT_QUEUE
2025-02-11 21:47:57.358--document_dlq_routing_key DOCUMENT_DLQ_ROUTING_KEY
2025-02-11 21:47:57.358--document_routing_key DOCUMENT_ROUTING_KEY
2025-02-11 21:47:57.358--document_dlq DOCUMENT_DLQ
2025-02-11 21:47:57.359process_document_queue.py: error: the following arguments are required: --amqp_uri, --paperless_uri
2025-02-11 21:47:57.358[--document_type DOCUMENT_TYPE]
2025-02-11 21:47:57.358[--document_date DOCUMENT_DATE]
@etsiot
Copy link
Author

etsiot commented Feb 11, 2025

error appearing after upgrade, impacts all flows of type python.Commands

Image

@anna-geller anna-geller added bug Something isn't working area/backend Needs backend code changes labels Feb 11, 2025
@anna-geller
Copy link
Member

@loicmathieu let's have a look or assign someone else from the team, maybe an issue for Matt from dynamic properties change?

@loicmathieu
Copy link
Member

Long commands are breaking the flows.

This has been fixed in #7360, this was due to double-quotes inside a lit of String which was not correctly handled.

error appearing after upgrade, impacts all flows of type python.Commands

This one is strange and I cannot reproduce it either in develop or in 0.21.2.
How do you update Kestra? We made fixes on the plugin-script-python plugin so if you use the last version it should not occurs.

@etsiot
Copy link
Author

etsiot commented Feb 12, 2025

Long commands are breaking the flows.

This has been fixed in #7360, this was due to double-quotes inside a lit of String which was not correctly handled.

error appearing after upgrade, impacts all flows of type python.Commands

This one is strange and I cannot reproduce it either in develop or in 0.21.2. How do you update Kestra? We made fixes on the plugin-script-python plugin so if you use the last version it should not occurs.

I update the kestra image tag in my compose file; are there more steps involved?
see below:
kestra:
image: kestra/kestra:v0.21.2
container_name: kestra
restart: always
user: "root"
privileged: true
command: server standalone --worker-thread=128 --config /etc/config/application.yaml

in the flows I use task type: io.kestra.plugin.scripts.python.Commands

@loicmathieu
Copy link
Member

I update the kestra image tag in my compose file; are there more steps involved?

Not, this is correct.

@etsiot
Copy link
Author

etsiot commented Feb 12, 2025

A full track record in case I haven't clarified in my posts in the Slack channel;

  • until 0.20 I was using calls to python scripts with line breaks, without any issues as below:
-          commands:
                - python scripts/paperless_api_post_document.py \
                  "{{ kv('paperless_base_uri','paperless') }}" \
                  "{{ kv('paperless_api_token','paperless' ) }}" \
                  "{{ inputs.customer }}" \
                  "{{ inputs.customer_id }}" \
                  '"{{ outputs.assess_file.vars.assessment.metadata.path }}"' \
                  '"{{ outputs.assess_file.vars.assessment.metadata.title }}"' \
                  '"{{ outputs.assess_file.vars.assessment.metadata.extension }}"' \
                  '"{{ outputs.assess_file.vars.assessment.metadata.path }}"' \
                  '"{{ outputs.assess_file.vars.assessment.metadata.modified }}"' \
                  '{{ outputs.assess_file.vars.tags }}' 
  • upgrading to 0.21 these flows started throwing errors.
    - did a clean install to 0.21 recreating the flows, using single, long lines which worked
  • upgrading to 0.21.1 was OK, no issue
  • then upgrading to 0.21.2 produced the error in screenshot above as well as forced me to do the following steps to get the flows working again:
  1. break the lines in commands to be able to save the flows
  2. recombine commands in one line & save the flows again to get them working

@Ben8t
Copy link
Member

Ben8t commented Feb 12, 2025

For reference, here is a sample flow (long commands with python script), it works fine on develop:

id: hyena_482026
namespace: company.team

tasks:
  - id: hello
    type: io.kestra.plugin.scripts.python.Commands
    inputFiles:
      main.py: |
        import argparse
        import sys

        def process_arguments(name, age, city, occupation, favorite_color, pet_name, hobby, coffee_preference, lucky_number):
            print(f"\nPerson Information Summary:")
            print(f"==========================")
            print(f"Name: {name}")
            print(f"Age: {age}")
            print(f"Location: {city}")
            print(f"Occupation: {occupation}")
            print(f"Favorite Color: {favorite_color}")
            print(f"Pet's Name: {pet_name}")
            print(f"Hobby: {hobby}")
            print(f"Coffee Preference: {coffee_preference}")
            print(f"Lucky Number: {lucky_number}")

        def main():
            parser = argparse.ArgumentParser(description='Process multiple personal information arguments')
            
            # Adding arguments
            parser.add_argument('--name', type=str, required=True, help='Person\'s name')
            parser.add_argument('--age', type=int, required=True, help='Person\'s age')
            parser.add_argument('--city', type=str, required=True, help='City of residence')
            parser.add_argument('--occupation', type=str, required=True, help='Current occupation')
            parser.add_argument('--favorite-color', type=str, required=True, help='Favorite color')
            parser.add_argument('--pet-name', type=str, required=True, help='Pet\'s name')
            parser.add_argument('--hobby', type=str, required=True, help='Favorite hobby')
            parser.add_argument('--coffee', type=str, required=True, help='Coffee preference')
            parser.add_argument('--lucky-number', type=int, required=True, help='Lucky number')

            args = parser.parse_args()

            # Process the arguments
            process_arguments(
                args.name,
                args.age,
                args.city,
                args.occupation,
                args.favorite_color,
                args.pet_name,
                args.hobby,
                args.coffee,
                args.lucky_number
            )

        if __name__ == "__main__":
            main()
    commands:
      - python main.py --name "John Doe" --age 30 --city "New York" --occupation "Developer" --favorite-color "Blue" --pet-name "Max" --hobby "Reading" --coffee "Black" --lucky-number 7

@etsiot
Copy link
Author

etsiot commented Feb 13, 2025

For reference, here is a sample flow (long commands with python script), it works fine on develop:

id: hyena_482026
namespace: company.team

a) Have you tried starting from 0.20 with such a flow and upgrade to 0.21.2?
b) can you do the same with a multi-line invocation?

@Ben8t
Copy link
Member

Ben8t commented Feb 13, 2025

Multi-line invocation works on develop. Not sure about starting from 0.20, upgrading to 0.21.2 yet

@Ben8t
Copy link
Member

Ben8t commented Feb 13, 2025

I'm not able to reproduce either moving from 0.20 to 0.21.2 (I installated 0.20, run the flow, upgrade to 0.21.2, run the flow. Everything is in succes)

image
image

Can you provide a screencast or reproducer so we can investiguate further please?

@Ben8t Ben8t added the kind/pending-feedback Idea waiting for user feedback label Feb 13, 2025
@etsiot
Copy link
Author

etsiot commented Feb 13, 2025

will try to get a screencast later today...

@Ben8t
Copy link
Member

Ben8t commented Feb 13, 2025

Ok, I'm able to reproduce:

  • install 0.21.1
  • run the flow
  • upgrade to 0.21.2
    the following error happens

image

Editing the flow solves it, but still an issue as you might not want to edit all your flows manually...

https://share.descript.com/view/sL3tLGb83yU

Also the flow with breaking lines and pebble expressions:

id: hyena_482026
namespace: company.team
variables:
  luck_number: 7
tasks:
  - id: hello
    type: io.kestra.plugin.scripts.python.Commands
    inputFiles:
      main.py: |
        import argparse
        import sys

        def process_arguments(name, age, city, occupation, favorite_color, pet_name, hobby, coffee_preference, lucky_number):
            print(f"\nPerson Information Summary:")
            print(f"==========================")
            print(f"Name: {name}")
            print(f"Age: {age}")
            print(f"Location: {city}")
            print(f"Occupation: {occupation}")
            print(f"Favorite Color: {favorite_color}")
            print(f"Pet's Name: {pet_name}")
            print(f"Hobby: {hobby}")
            print(f"Coffee Preference: {coffee_preference}")
            print(f"Lucky Number: {lucky_number}")

        def main():
            parser = argparse.ArgumentParser(description='Process multiple personal information arguments')
            
            # Adding arguments
            parser.add_argument('--name', type=str, required=True, help='Person\'s name')
            parser.add_argument('--age', type=int, required=True, help='Person\'s age')
            parser.add_argument('--city', type=str, required=True, help='City of residence')
            parser.add_argument('--occupation', type=str, required=True, help='Current occupation')
            parser.add_argument('--favorite-color', type=str, required=True, help='Favorite color')
            parser.add_argument('--pet-name', type=str, required=True, help='Pet\'s name')
            parser.add_argument('--hobby', type=str, required=True, help='Favorite hobby')
            parser.add_argument('--coffee', type=str, required=True, help='Coffee preference')
            parser.add_argument('--lucky-number', type=int, required=True, help='Lucky number')

            args = parser.parse_args()

            # Process the arguments
            process_arguments(
                args.name,
                args.age,
                args.city,
                args.occupation,
                args.favorite_color,
                args.pet_name,
                args.hobby,
                args.coffee,
                args.lucky_number
            )

        if __name__ == "__main__":
            main()
    commands:
      - python main.py --name "John Doe" \
      - --age 30 --city "New York" --occupation "Developer" --favorite-color "Blue" --pet-name "Max" --hobby "Reading" --coffee "Black" --lucky-number {{ vars.luck_number }}

@Ben8t Ben8t removed the kind/pending-feedback Idea waiting for user feedback label Feb 13, 2025
@loicmathieu loicmathieu assigned mgabelle and unassigned loicmathieu Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend Needs backend code changes bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

5 participants