Skip to content

Custom operator name field dont accept special characters #9840

@aladinoss

Description

@aladinoss

Apache Airflow version: 1.10.2 --> 1.10.11

Kubernetes version (if you are using kubernetes) (use kubectl version):

Environment:

  • Cloud provider or hardware configuration: Internal Cloud solution (VM hosting)
  • OS (e.g. from /etc/os-release): rhel 7.7
  • Kernel (e.g. uname -a): any
  • Install tools: pypi
  • Others:

What happened:

Cant import operator if name field contains special or caps character

What you expected to happen:

Load the operator even name contains special character

How to reproduce it:
just add special or caps characters to the class field name
example :

import logging

from airflow.models import BaseOperator
from airflow.plugins_manager import Airflowplugin
from airflow.utils.decorators import apply_defaults

log = logging.getLogger(__name__)

class DevMultiplyOperator(BaseOperator):

  @apply_defaults
  def __init__(self, my_operator_param, * args, ** kwargs):
    self.operator_param = my_operator_param
    super(DevMultiplyoperator, self).__init__( * args, ** kwargs)
  
  def execute(self, context):
    try:
       log.info('operator_param: %s', self.operator_param)
       if not isinstance(self.operator_param, int): 
            raise TypeError('Use integer as inputs.')
       return (self.operator_param * 5)
    except Exception as error:
       log.error(error) 
       raise

class DevMultiplyPlugin(AirflowPlugin):
  name = "dev_multiply_plugin"
  operators = [DevMultiplyoperator]

Anything else we need to know:
We are using plugins directory to host operators/hooks/sensor to better organize project.
/dags --> contains dags and subdags
/plugins --> contains operators/hooks/sensor
/config --> contains configuration files
/tests --> contains tests files

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions