#457 Remove usage of mutable default arguments
Closed: Fixed 4 years ago by qwan. Opened 4 years ago by lucarval.

Using mutable default arguments in Python is usually a bad idea. There are, at least, two places in this code base that make use of it.

in freshmaker/handlers/__init__.py:

469     @fail_artifact_build_on_handler_exception(whitelist=[ODCSComposeNotReady])                      
470     def build_image_artifact_build(self, build, repo_urls=[]):                                      
...                                           
...
556                 repo_urls.append(odcs_compose["result_repofile"])      

The append call actually changes the default argument!

In freshmaker/odcsclient.py:

101     def _fake_odcs_new_compose(                                                                     
102             self, compose_source, tag, packages=None, results=[],                                   
103             builds=None):
...
128         if results:                                                                                 
129             new_compose['results'] = ['boot.iso'] 

This one is weird... Why is ['boot.iso'] being used and not results? Looking at the calls to _fake_odcs_new_compose, the results argument may not actually be used.


Commit cc05c9b fixes this issue

Login to comment on this ticket.

Metadata
Related Pull Requests
  • #459 Merged 4 years ago