Skip to content

using none statement in bicepparam file crashes the Bicep CLI with a Python Exception #18220

@pgelinas

Description

@pgelinas

Bicep version
Bicep CLI version 0.38.33 (6bb5d5f)
"azure-cli": "2.77.0",

Describe the bug
A bicepparam with a using none statement crashes out with a Python exception. This using none should allow me to share the bicepparam file with different deployments, but it doesn't seem to work at all.

To Reproduce
This very simple bicepparam works properly

using 'main.bicep'

param environment = 'dev'

with the following simple main.bicep

param environment string
output env string = environment

Running this command az deployment group create -g test -f main.bicep --parameters main.dev.bicepparam.

But changing from using 'main.bicep' to using none and re-running the command results in a python exception
expected string or bytes-like object, got 'NoneType'

Additional context
Debug output

cli.knack.cli: Command arguments: ['deployment', 'group', 'create', '-g', 'hades', '-f', 'main.bicep', '--parameters', 'main.dev.bicepparam', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.                                                                                                                                                                                                                                                                                           
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7ff287fb8fe0>, <function OutputProducer.on_global_arguments at 0x7ff287d30cc0>, <function CLIQuery.on_global_arguments at 0x7ff287d5ade0>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'deployment': ['azure.cli.command_modules.resource']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: resource                  0.130        52       234
cli.azure.cli.core: Total (1)                 0.130        52       234
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name                  Load Time    Groups  Commands  Directory
cli.azure.cli.core: Total (0)                 0.000         0         0  
cli.azure.cli.core: Loaded 52 groups, 234 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : deployment group create
cli.azure.cli.core: Command table: deployment group create
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7ff286fc22a0>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/root/.azure/commands/2025-10-09.12-44-39.deployment_group_create.5292.log'.
az_command_data_logger: command args: deployment group create -g {} -f {} --parameters {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x7ff286ff7560>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x7ff28701d8a0>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x7ff28701da80>, <function register_upcoming_breaking_change_info.<locals>.update_breaking_change_info at 0x7ff28701db20>]                                                                                                                                                                                                                                                                                             
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7ff287d30d60>, <function CLIQuery.handle_query_parameter at 0x7ff287d5ae80>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x7ff28701d940>]
cli.azure.cli.command_modules.resource._bicep: Current value of "use_binary_from_path": false.
cli.azure.cli.command_modules.resource._bicep: Current value of "use_binary_from_path": false.
cli.azure.cli.command_modules.resource._bicep: Current value of "use_binary_from_path": false.
cli.azure.cli.command_modules.resource._bicep: Bicep CLI installation path: /root/.azure/bin/bicep
cli.azure.cli.command_modules.resource._bicep: Bicep CLI installed: True.
urllib3.connectionpool: Starting new HTTPS connection (1): aka.ms:443
urllib3.connectionpool: https://aka.ms:443 "GET /BicepLatestRelease HTTP/1.1" 301 0
urllib3.connectionpool: Starting new HTTPS connection (1): downloads.bicep.azure.com:443
urllib3.connectionpool: https://downloads.bicep.azure.com:443 "GET /releases/latest HTTP/1.1" 200 54486
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job                                                                                                                                                                                                            
    result = cmd_copy(params)                                                                                                                                                                                                                                                                                       
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__                                                                                                                                                                                                            
    return self.handler(*args, **kwargs)                                                                                                                                                                                                                                                                            
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                            
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler                                                                                                                                                                                                    
    return op(**command_args)                                                                                                                                                                                                                                                                                       
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/resource/custom.py", line 603, in deploy_arm_template_at_resource_group                                                                                                                                                                      
    return _deploy_arm_template_at_resource_group(cmd=cmd,                                                                                                                                                                                                                                                          
                                                  resource_group_name=resource_group_name,                                                                                                                                                                                                                          
    ...<4 lines>...                                                                                                                                                                                                                                                                                                 
                                                  no_prompt=no_prompt, template_spec=template_spec, query_string=query_string,                                                                                                                                                                                      
                                                  validation_level=validation_level)                                                                                                                                                                                                                                
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/resource/custom.py", line 636, in _deploy_arm_template_at_resource_group                                                                                                                                                                     
    deployment_properties = _prepare_deployment_properties_unmodified(cmd, 'resourceGroup', template_file=template_file,                                                                                                                                                                                            
                                                                      template_uri=template_uri,                                                                                                                                                                                                                    
    ...<2 lines>...                                                                                                                                                                                                                                                                                                 
                                                                      no_prompt=no_prompt, template_spec=template_spec,                                                                                                                                                                                             
                                                                      query_string=query_string, validation_level=validation_level)                                                                                                                                                                                 
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/resource/custom.py", line 1162, in _prepare_deployment_properties_unmodified                                                                                                                                                                 
    template_obj = _remove_comments_from_json(template_content)                                                                                                                                                                                                                                                     
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/resource/custom.py", line 359, in _remove_comments_from_json                                                                                                                                                                                 
    template = re.sub(r'(^[\t ]*//[\s\S]*?\n)|(^[\t ]*/\*{1,2}[\s\S]*?\*/)', '', template, flags=re.M)                                                                                                                                                                                                              
  File "/opt/az/lib/python3.13/re/__init__.py", line 208, in sub                                                                                                                                                                                                                                                    
    return _compile(pattern, flags).sub(repl, string, count)                                                                                                                                                                                                                                                        
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                        
TypeError: expected string or bytes-like object, got 'NoneType'                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                    
During handling of the above exception, another exception occurred:                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                                                                                                                                                  
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/arm.py", line 109, in handle_template_based_exception                                                                                                                                                                                          
    raise CLIError(ex.inner_exception.error.message)                                                                                                                                                                                                                                                                
                   ^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                               
AttributeError: 'TypeError' object has no attribute 'inner_exception'                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                    
During handling of the above exception, another exception occurred:                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                                                                                                                                                  
  File "/opt/az/lib/python3.13/site-packages/knack/cli.py", line 233, in invoke                                                                                                                                                                                                                                     
    cmd_result = self.invocation.execute(args)                                                                                                                                                                                                                                                                      
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute                                                                                                                                                                                                             
    raise ex                                                                                                                                                                                                                                                                                                        
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially                                                                                                                                                                                                  
    results.append(self._run_job(expanded_arg, cmd_copy))                                                                                                                                                                                                                                                           
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                            
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_job                                                                                                                                                                                                            
    return cmd_copy.exception_handler(ex)                                                                                                                                                                                                                                                                           
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^                                                                                                                                                                                                                                                                           
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/arm.py", line 114, in handle_template_based_exception                                                                                                                                                                                          
    raise CLIError(ex)                                                                                                                                                                                                                                                                                              
knack.util.CLIError: expected string or bytes-like object, got 'NoneType'                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                    
cli.azure.cli.core.azclierror: expected string or bytes-like object, got 'NoneType'

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions