I have a piece of code below (belongs to a Django admin view, slightly modified). My IDE (PyCharm) warns me at the last line that Local variable 'ModelForm' might be referenced before assignment
.
I don't see how that can ever happen, but when I comment out line 6:
with transaction.commit_manually():
then the warning disappears.
Am I missing something, or is PyCharm missing something?
Here is the chunk of code. I striped it down to just a few lines and it still gives the warning. The original chunk of code is here (70 lines): http://pastebin.com/4UT9hRPb
ModelForm = self.get_form(request, obj, form=form)
formsets = []
if request.method == 'POST':
# commit only when all forms are valid
with transaction.commit_manually():
try:
objects = queryset.all()
transaction.commit()
return self.response_change(request, new_object)
finally:
general_error = unicode(sys.exc_info()[1])
transaction.rollback()
form = ModelForm()