Wednesday, June 25, 2008

Django and Python - No Multiple Heterogeneous Database Support

Django and Python - No Multiple Heterogeneous Database Support


I Like Python


I really do, but can't say the same about Django. I recently had the freedom to start a new small project, and as you may remember I work with Asterisk, so the project was a report centric application where you can define the diferent parameters for your report, and save them as presets.

I had been playing with Django and even followed the tutorials on the official site, so, since I had the freedom to decide how to do it, I thought it would be a good test of the framework to see how it compared in real life to Ruby and Rails. It seemed really promising, and although I was a bit worried about the lack of official support for a specific AJAX framework, I also thought this could be beneficial, since that meant I could actually choose a different framework (like I couldn't with Rails, right?, well, that encouraged me at the time).

You mean, like plug-ins but better?

So I started building the project, then the app, that's how it's done in Django, a project, can have several applications, which are like modules, that do specific parts of a whole site, also you can use an app in several projects, kinda nice if you think about it, like plugins, but better in a sense, feels more natural).

Batteries Included

Set up the admin part, Django comes with the administration batteries included, like AjaxScaffold included, but without the AJAX, you just define -- In the model!? -- the administrative aspects.

I can't see how the administrative details (obviously more in the V part of MVC) could fit in the Model (The M in MVC), but what the heck, it came free, and although it seemed a bit odd, I carried with it.

I Like Big Buts, And I Cannot Lie

Up to this point everything was good, I had set up the models for the reports, the administrative part and was just about to set up a Controller/View to create reports, and for this I needed to interact with the Asterisk MySQL database (I didn't mention, but I was required to have this app's specific databases in SQLite3, and yet interact with MySQL to get the reports' data), But, and that's a big But (I like big Buts) Oh surprise!, I just couldn't, unless I patched django, and even if I did I wouldn't be able to use the administrative aspects of a django application with the external database.

That Sucks

It does, I usually develop small applications that get deployed to 40+ (and growing) servers, and try to automate the deployment as much as I can so I dont get nagged by the guys that actually do the deployments with silly questions, comments or complaints.

This meant that I would have to keep a private branch of Django with the patch, or have it available somewhere for our needs, or otherwise, show the config mgmt guys how to (and why) they had to patch django itself.

Besides, it didn't feel right.

No Django for Me? :(

So after a short thought about it, I decided to rm -rf it and start over in Rails.

Ruby and Rails still have to be deployed to every new server we manage, but It can be installed relatively simply with a shell script and doesn't have to be patched (the part I don't like).

Ruby and Rails can, at times be a PITA to install and get set up, specially in non-standard configurations, but at least I won't have to start all over again.

So this post was about one thing that may not be apparent when you start programming in Python on Django,

Conclusion

Python on Django DOES NOT SUPPORT Multiple Heterogeneous Databases.

That said,

I rest my case.

P.S. : I know I use to many parenthesis (I like them) and also, If I am wrong and didn't google well, please let me know if Django can interact with external databases in a NATURAL WAY (don't bother commenting that patching is not that hard and stuff like that).

Thanks everyone!.