Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Djongo itself is not compatible with its dependencies #670

Open
AryanHamedani opened this issue Jun 6, 2023 · 7 comments
Open

The Djongo itself is not compatible with its dependencies #670

AryanHamedani opened this issue Jun 6, 2023 · 7 comments

Comments

@AryanHamedani
Copy link

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
Copy link

same bug TAT

@Hnitrogen
Copy link

#585 issue fix this

pip install pymongo===3.12.1 

@AryanHamedani
Copy link
Author

AryanHamedani commented Jun 17, 2023

#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
Copy link
Author

AryanHamedani commented Jun 17, 2023

#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
Copy link

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
Copy link
Author

AryanHamedani commented Jun 27, 2023

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
Copy link

Issue is still here after 1 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants