doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.86k stars 351 forks source link

The Djongo itself is not compatible with its dependencies #670

Open AryanHamedani opened 1 year ago

AryanHamedani commented 1 year ago

Djongo does not work with its own dependency!

The problem is that the bool magic method was not implemented in the latest pymongo ( I don't exactly know from which version of pymongo, this have changed ) and now when the djongo wants to check the exist of the database connection it will raises an error, the problem solved when I removed pymongo 4 and start using pymongo 3.12 but the djongo will install the latest pymongo as its dependency which does not work.

When I just executed:

python manage.py makemigrations

Traceback

Traceback (most recent call last):
  File "/home/p0s3id0n/Code/Practices/mongoengine-vs-djongo-practice-project/djongo_test_project/manage.py", line 22, in <module>
    main()
  File "/home/p0s3id0n/Code/Practices/mongoengine-vs-djongo-practice-project/djongo_test_project/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/django/core/management/base.py", line 415, in run_from_argv
    connections.close_all()
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/django/utils/connection.py", line 85, in close_all
    conn.close()
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/django/db/backends/base/base.py", line 358, in close
    self._close()
  File "/home/p0s3id0n/.virtualenvs/practices/lib/python3.11/site-packages/djongo/base.py", line 208, in _close
    if self.connection:
  File "/home/p0s3id0n/.virtualenvs/practices/lib64/python3.11/site-packages/pymongo/database.py", line 1161, in __bool__
    raise NotImplementedError(
NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None
Hnitrogen commented 1 year ago

same bug TAT

Hnitrogen commented 1 year ago

#585 issue fix this

pip install pymongo===3.12.1 
AryanHamedani commented 1 year ago

#585 issue fix this

pip install pymongo===3.12.1 

Yes, it can be fixed like that, But I think it's not right that a popular package like Djongo has this kind of issue Hopefully, somebody from their team sees this issue and fix this problem which is only in the package version number, if there are other dependencies on the higher versions of PyMongo (which I'm not aware of), then I think the code for checking the connection should change, anyway if somebody from Djongo team or contributors have any idea on this, I will be happy if you tell me what is happening, if not, maybe I fix that and try a pull request :D

AryanHamedani commented 1 year ago

#585 issue fix this

pip install pymongo===3.12.1 

Yes, it can be fixed like that, But I think it's not right that a popular package like Djongo has this kind of issue Hopefully, somebody from their team sees this issue and fix this problem which is only in the package version number if there are other dependencies on the higher versions of PyMongo (which I'm not aware of), then I think the code for checking the connection should change, anyway if somebody from Djongo team or contributors have any idea on this, I will be happy if you tell me what is happening, if not, maybe I fix that and try a pull request :D

I double-checked the code in the master branch with the package I was using on my local computer (considering that I used pip install djongo command to install the package and version 1.3.6 was installed by default ), the problem has been solved in the latest code in the master branch, but the new package was not released yet, so the error exists for now but there is not anything to fix, release the new one, please

PlainStack commented 1 year ago

I'm also geting the same error "NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None". Unable to use makemigrations and use the package.

Is the only fix to rollback pymango to version 3.12.1?

AryanHamedani commented 1 year ago

I'm also geting the same error "NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None". Unable to use makemigrations and use the package.

Is the only fix to rollback pymango to version 3.12.1?

I think for now it is the best solution, but if you are able to understand the code you can also change the code of the base module where it raises the error, and instead of doing if db. connection, write if db. connection is None, it should fix the error too, but the first way is more straightforward and easier.

matteolavaggi commented 4 months ago

Issue is still here after 1 years.