Skip to content

[Bug]: Mutable default arguments used in Formstack API methods #4907

Description

@rupayanjas

Description

Several methods in esp/formsstack/api.py use mutable default arguments (args = {}).

Examples:

def delete(self, id, args = {}):
def create_field(self, form, args = {}):
def __request(self, method, args = {})

Using mutable objects like {} as default parameters in Python is unsafe because the same object instance is reused across function calls. If the dictionary is modified during one call, the modified state persists in subsequent calls, which can lead to unintended side effects and hard-to-trace bugs.

The recommended pattern is to use None as the default value and initialize the dictionary inside the function.

Steps to Reproduce

  1. Open the file esp/formsstack/api.py.
  2. Locate the following methods:
    • delete(self, id, args = {})
    • create_field(self, form, args = {})
    • __request(self, method, args = {})
  3. Observe that a mutable default argument ({}) is used.
  4. If the dictionary is modified during a call, the same mutated object may be reused in later calls.

Expected Behavior

Functions should avoid mutable default arguments.

The safer pattern is:

def delete(self, id, args=None):
if args is None:
args = {}

This ensures a new dictionary is created for every function call.

Actual Behavior

The methods currently define args with a default value of {}, which causes Python to reuse the same dictionary instance between function calls.

This may lead to unexpected behavior if the dictionary is modified during execution.

Screenshots

No response

Operating System

No response

Browser

No response

Additional Context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions