You’re going to have to do some debugging. Comment out unnecessary lines, calculations etc. use a fixed value, use a default creator etc. then carefully step through the logic. Are you using global values inside the function? Is this a method inside a class or a function? Without all the code it is impossible to assess.
As a friendly reminder please see item 7 of the FAQs
What’s this for after you set the value?
In python syntax convention variables with capitals are used for classes