Django, Djongo and SQLParse dependency

Hi everyone,

I am trying to connect my Django application to my MongoDB Atlas database using Djongo as my database engine. The Djongo package require sqlparse=0.2.4. However, at the same time it requires Django to be >=2.1 and <=3.0.5. The issue is that I am using conda to manage my environment and I installed Django 3.0.3 which has a dependency sqlparse=0.3.1 (???). I manually uninstalled the 0.3.1 version using “conda remove” and tried to install the 0.2.4 version. As expected I got an error saying that my environment will be inconsistent due to Django 3.0.3 requiring the sqlparse 0.3.1 version.

Obviously since I am using Djongo my sqlparse has to be of the 0.2.4 version. I am new to Django and MongoDB so I am not quite sure how I can solve this correctly. So my question is, can Django 3.0.3 work with sqlparse=0.2.4? And if not then what version of Django is it recommended to install to solve this issue?

Thanks for your help.

From what I can see and quickly determine, Django 3.0.6 only has a requirement for sqlparse >= 0.2.2, which means that sqlparse 0.2.4 should work fine with it.

(I just tested a pip install of Django 3.0.6 with sqlparse==0.2.4 and didn’t get any warnings or errors. Didn’t try running anything with it, so I don’t know if there are any more subtle problems that could be encountered.)

Snippets:

 pip install django==3.0.3
Collecting django==3.0.3
  Downloading Django-3.0.3-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 1.4 MB/s 
Requirement already satisfied: sqlparse>=0.2.2 in /home/tskww/ve/d38/lib/python3.8/site-packages (from django==3.0.3) (0.2.4)
Requirement already satisfied: pytz in /home/tskww/ve/d38/lib/python3.8/site-packages (from django==3.0.3) (2019.3)
Requirement already satisfied: asgiref~=3.2 in /home/tskww/ve/d38/lib/python3.8/site-packages (from django==3.0.3) (3.2.7)

and

pip install django==3.0.6
Collecting django==3.0.6
  Using cached Django-3.0.6-py3-none-any.whl (7.5 MB)
Requirement already satisfied: asgiref~=3.2 in /home/tskww/ve/d38/lib/python3.8/site-packages (from django==3.0.6) (3.2.7)
Requirement already satisfied: sqlparse>=0.2.2 in /home/tskww/ve/d38/lib/python3.8/site-packages (from django==3.0.6) (0.2.4)
Requirement already satisfied: pytz in /home/tskww/ve/d38/lib/python3.8/site-packages (from django==3.0.6) (2019.3)
1 Like

Is there any chance that the Django version available on Conda has different requirements than the one on pip by mistake?

Thanks for your reply!

Sorry, I can’t help you there - maybe someone else knows?

It’s possible that there’s an ancillary package included in that conda version having a dependency on a higher version of sqlparse. I don’t know enough about it to do anything other than make guesses.

I would guess that given what sqlparse and Djongo do, that it’s more likely that Djongo would work with the higher version of sqlparse rather than the other libraries working with the older version. While it’s by no means guaranteed, generally speaking, newer versions tend to add features more than remove them.

I guessed so too so I tried to use sqlparse==0.3.1 to see if I could get away with it. However, Djongo throws an SQLDecodeError exception so I downgraded to sqlparse==0.2.4 and it seems like the issue has been resolved.

Thanks for your help!

For anyone having the same issue this is my current environment (it works for now):
-> django==3.0.3
-> djongo==1.3.2
-> dnspython==1.16.0 (not required by djongo but is required by pymongo for mongodb+srv urls)
-> pymongo==3.10.1
-> python==3.6.10
-> sqlparse==0.2.4