psycopg2 mx.DateTime issue quick fix

If you ever get the dreaded mx.DateTime psycopg2 error when running django tests, (this is for psycopg2 == 2.4.1) this is because when you’re in a virtualenv the python mx libraries don’t transfer over
some reason. the quick fix is to pip install egenix-mx-base and you should be good to go. for reference latest versions of psycopg2 seem to have an issue with transaction commits during unit tests, for now i’m running psycopg2==2.4.1, anything newer runs into the autocommit issue for unit tests.

good postgresql required reading

http://thebuild.com/presentations/not-your-job.pdf

Postgresql: when it’s not your job. Basic settings tweaks for performance and logging – proving to be very handy in figuring out some issues currently plaguing a server right now. Hoping in the future to fabric/chef this to automagically set the settings – especially logging stuffs.
python xml pretty printing
I’m going to add this to the printing.py file in the dimagi-utils project:

instead of calling xmllint from the filesystem, just use the lxml library for prettifying xml printouts.
I’ve added an optional arg to return it in case you need it elsewhere.
def print_pretty_xml(xml_string, do_print=True):
    “””
    Use lxml to make a fancy formatted xml string.
    Optional if do_print is false, just return the string for additional usage.
    “””
    root_node = lxml.etree.fromstring(xml_string)
    output = lxml.etree.tostring(root_node, pretty_print=True)
    if do_print:
        print output
    else:
        return output