Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning output on manage.py dumpdata?

Tags:

django

I'm using django's dumpdata and loaddata commands to facilitate some data exports. However I currently have some unresolved deprecation warnings and so when I write the output of dumpdata to a file the warnings end up at the top of the file and I must manually clean up the dump files every time. Is there any way to suppress or avoid the warnings do that the output of dumpdata is legitimate json without having to manually remove the warning text each time?

like image 488
B Robster Avatar asked Feb 22 '13 20:02

B Robster


2 Answers

you can also suppress warnings without having to insert code anywhere, by flags on the python interpreter

eg

python -Wi manage.py dumpdata

https://docs.python.org/2/using/cmdline.html#cmdoption-W

like image 160
Anentropic Avatar answered Oct 22 '22 01:10

Anentropic


You could try overriding warning.showwarning. Put the following code somewhere that will be imported when you dumpdata (such as your settings.py):

import warnings
warnings.showwarning = lambda *x: None
like image 26
dgel Avatar answered Oct 22 '22 02:10

dgel