django_neomodel can't find attribute MAX_POOL_SIZE - python

I am trying to set my first Django project using neo4j as database and neomodel as OGM, so I am following this directions. Nevertheless, when a try to start Django server, I get this error:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.8/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python#3.8/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django_neomodel/apps.py", line 20, in ready
self.read_settings()
File "/Users/hugovillalobos/Documents/Code/attractoraproject/attractora_backend/AttractoraVenv/lib/python3.8/site-packages/django_neomodel/apps.py", line 17, in read_settings
config.MAX_POOL_SIZE = getattr(settings, 'NEOMODEL_MAX_POOL_SIZE', config.MAX_POOL_SIZE)
AttributeError: module 'neomodel.config' has no attribute 'MAX_POOL_SIZE'
I am using python 3.7 and Django 3.1.4.
EDIT
These are my settings, as directions state, and I have no code yet, I just want to start Django server with this settings.
NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://neo4j:test#localhost:7687')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_neomodel',
'rest_framework',
]

I ran into the same problem and am still not quite sure why it's happening. This error message is getting thrown by the apps.py file in neomodel-django:
def read_settings(self):
config.DATABASE_URL = getattr(settings, 'NEOMODEL_NEO4J_BOLT_URL', config.DATABASE_URL)
config.FORCE_TIMEZONE = getattr(settings, 'NEOMODEL_FORCE_TIMEZONE', False)
config.ENCRYPTED_CONNECTION = getattr(settings, 'NEOMODEL_ENCRYPTED_CONNECTION', False)
config.MAX_CONNECTION_POOL_SIZE = getattr(settings, 'NEOMODEL_MAX_CONNECTION_POOL_SIZE', config.MAX_CONNECTION_POOL_SIZE)
It looks like if you set NEOMODEL_MAX_CONNECTION_POOL in the django settings file it should provide the correct value except that wasn't working for me. The default value provided in getattr (config.MAX_CONNECTION_POOL_SIZE) is a property of the neomodel config object / module and is apparently not set by default. For whatever reason, getattr was trying to grab this default and the attribute doesn't exist by default.
I figured I'd see what happened if I manually set config.MAX_CONNECTION_POOL_SIZE. Good news, it worked! So, I just added this to my settings.py:
from neomodel import config
config.MAX_POOL_SIZE = 50
I confess I've not used getattr much, so I played around with it to get a better understanding of how it works. Here's the function definition:
getattr(object, name[, default])
If default is set to an attribute that doesn't exist of an object or module, then getattr immediately throws an AttributeError, even IF the object and name values are valid and would otherwise return a value.
So it seems this is a bug in the django-neomodel code? It's expecting MAX_CONNECTION_POOL_SIZE to be set in the neomodel config but this is not the case, at least as of 1/22/21 using neomodel 4.0.1 and django-neomodel 0.0.4 .

Download django_neomodel package from git with the below command :
pip install -e git+https://github.com/neo4j-contrib/django-neomodel.git#egg=django-neomodel
As the config file from the neomodel package contains MAX_POOL_SIZE setting when installed django_neomodel with pip install django_neomodel instead of MAX_CONNECTION_POOL_SIZE

Related

Django/cookiecutter-django Error: "AttributeError: 'Path' object has no attribute 'endswith''" with manage.py makemigrations

I have been trying to set up Django with a cookiecutter-django project
with cookiecutter https://github.com/pydanny/cookiecutter-django.git
and I get this error output when I run ./manage.py makemigrations at the end.
My python version in the virturalenv is Python 3.5.2
This is the tail of console output and not from a file.
Stack overflow doesn't allow me to post all of the long error output without more of other text.
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/db/models/base.py", line 156, in __new__
new_class.add_to_class(obj_name, obj)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/db/models/fields/related.py", line 1588, in contribute_to_class
self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/db/models/fields/related.py", line 1057, in create_many_to_many_intermediary_model
'verbose_name': _('%(from)s-%(to)s relationship') % {'from': from_, 'to': to},
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/functional.py", line 192, in __mod__
return str(self) % rhs
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/functional.py", line 156, in __text_cast
return func(*self.__args, **self.__kw)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/translation/__init__.py", line 79, in gettext
return _trans.gettext(message)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/translation/trans_real.py", line 285, in gettext
_default = _default or translation(settings.LANGUAGE_CODE)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/translation/trans_real.py", line 198, in translation
_translations[language] = DjangoTranslation(language)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/translation/trans_real.py", line 99, in __init__
self._add_local_translations()
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/translation/trans_real.py", line 151, in _add_local_translations
translation = self._new_gnu_trans(localedir)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/site-packages/django/utils/translation/trans_real.py", line 123, in _new_gnu_trans
fallback=use_null_fallback,
File "/usr/lib/python3.5/gettext.py", line 428, in translation
mofiles = find(domain, localedir, languages, all=True)
File "/usr/lib/python3.5/gettext.py", line 396, in find
mofile = os.path.join(localedir, lang, 'LC_MESSAGES', '%s.mo' % domain)
File "/root/painlesslanguage/painlesslanguageenv/lib/python3.5/posixpath.py", line 84, in join
elif not path or path.endswith(sep):
AttributeError: 'Path' object has no attribute 'endswith'
I left the TIME_ZONE cookiecutter-django setup option blank if that matters.
this seems to be a difficult error to fix or even debug.
some users have gotten this error when they have not included the static url properly in settings.py of left a trailing comma in the INSTALLED_APPS declaration.
however i got this error just when i switched a python version.
I ended up somehow solving it (at the time) by reinstalling python and relinking pyenv python to brew.
however, now its returned. there must be a way to debug this.
all the stacktrace points to files in the python install or only to the settings file. but if your settings file looks fine, its really hard to know how to fix it. After checking your settings.py INSTALLED_APPS (to check there are no trailing commas) id suggest reinstalling python and see if that helps.
if that doesnt work, then what helped me was printing out the apps being installed. to do this you will have to add print lines into the python/django code where the errors are thrown. as by default this info isnt being sent to the application layer, though it should be. these will be removed if you ever change the py install again. so its kind of a temperoray/local way to help u debug. really the framework should send the name info if it fails to import an app. by adding these lines i found what was going wrong with my import.

Error while Django Database Backup - AttributeError: 'NoneType' object has no attribute 'extension'

I am trying to use django-dbbackup v2.3.3 to backup the database of django project (django-1.8.4, python - 3.4.3)
I am following this django-dbbackup documentation.
Below is my project settings for DATABASES and DATABASE_BACKUP
INSTALLED_APPS = (
'django.contrib.auth',
'django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'authtools',
'crispy_forms',
'easy_thumbnails',
'rest_framework',
'dbbackup',
'profiles',
'location',
'maps'
)
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.spatialite'
# DATABASE BACKUP SETTINGS
DBBACKUP_STORAGE = 'dbbackup.storage.filesystem_storage'
DBBACKUP_STORAGE_OPTIONS ={'location':'/home/altius/locateme/src/backup/'}
And I am getting the following error -
Backing Up Database: db.sqlite3
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File"/usr/local/lib/python3.4/distpackages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/dbbackup/utils.py", line 100, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/dbbackup/management/commands/dbbackup.py", line 54, in handle
self.save_new_backup(database)
File "/usr/local/lib/python3.4/dist-packages/dbbackup/management/commands/dbbackup.py", line 66, in save_new_backup
filename = self.dbcommands.filename(self.servername)
File "/usr/local/lib/python3.4/dist-packages/dbbackup/dbcommands.py", line 278, in filename
extension = self.settings.extension
AttributeError: 'NoneType' object has no attribute 'extension'
I tried to look into other errors but in vain to find out the solution for
AttributeError: 'NoneType' object has no attribute 'extension'
There are several AttributeError like append, strip, format etc. but not able to find extension error.
Am I missing some more settings ? What else need to do to get rid of this error to backup the database locally for django-project ?
From its source code, I think django-dbbackup doesn't have support for SpatiaLite.
Check the source of method _get_settings() (which sets the value of self.settings) it shows that the code is fetching database settings for only MySQL, PostGIS, PostGreSQL and SQLite.
Since, it matches none of the listed databases, self.settings gets set to None and hence when you get the error AttributeError: 'NoneType' object has no attribute 'extension' when it tries to fetch self.settings.extension. You can give it a try in Python shell.
>>> settings = None
>>> settings.extension
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
settings.extension
AttributeError: 'NoneType' object has no attribute 'extension'
Although, there is no specific mention of the list of databases django-dbbackup supports in the docs. It would be better if you could confirm this once with the authors.
EDIT: OP has created an issue on the GitHub repo of django-backup. Do check the link to check for updates regarding support for SpatiaLite.

AttributeError: 'NoneType' object has no attribute '_default_manager' when running lettuce with django rest framework

I am trying to use lettuce to implement BDD for creating an rest framework api but when I execute the command python manage.py harvest I get following error
/rest_framework/serializers.py", line 818, in get_related_field
'queryset': related_model._default_manager,
AttributeError: 'NoneType' object has no attribute '_default_manager'
Detailed stack trace is:
(envSamplePayApp)root#ubuntu:/pythonWorkspace/samplePayProject# python manage.py harvest
Django's builtin server is running at 0.0.0.0:8000
Traceback (most recent call last):
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/lettuce/django/management/commands/harvest.py", line 167, in handle
result = runner.run()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/lettuce/__init__.py", line 137, in run
self.loader.find_and_load_step_definitions()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/lettuce/fs.py", line 49, in find_and_load_step_definitions
module = __import__(to_load)
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/tests/test_serializer_import.py", line 4, in <module>
from rest_framework.tests.accounts.serializers import AccountSerializer
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/tests/accounts/serializers.py", line 6, in <module>
class AccountSerializer(serializers.ModelSerializer):
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/tests/accounts/serializers.py", line 8, in AccountSerializer
admins = UserSerializer(many=True)
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 196, in __init__
self.fields = self.get_fields()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 232, in get_fields
default_fields = self.get_default_fields()
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 716, in get_default_fields
field = self.get_related_field(model_field, related_model, to_many)
File "/pythonWorkspace/samplePayProject/envSamplePayApp/local/lib/python2.7/site-packages
All the code can be found at downloadcode.
Note when I run the api from browser it works fine.
What is causing the AttributeError: 'NoneType' object has no attribute '_default_manager'?
I ran into this error just now. The cause of my error was due to the fact that I had created a ManyToManyField from Model X of App A to Model Y of App B. When I tried to create schema migration via python manage.py schemamigration --auto app_a, it raised this error because I had yet to:
include 'app_b' in the INSTALLED_APPS tuple of settings.py
not having created the initial schema migration for app_b (which would not be possible with adding app_b to INSTALLED_APPS).
Effectively, I linked to an model that was not known at the time. Hopefully this can help someone in the future.
EDIT: Actually, on further inspection, I realize now the reason that this error is being raised so ambiguously is because of django-debug-toolbar. Apparently DjangoDebugToolbar is causing some issues around errors propagating properly. Disabling it in INSTALLED_APPS allowed the errors to become apparent.

django.contrib.comments.moderation.AlreadyModerated error in zinnia django

I had a django app in which i am using django-zinnia-blog for my blog functionality.
Issue One
And now i updated zinnia with latest github version and i am getting the below wierd error
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x941554c>>
Traceback (most recent call last):
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
self.validate(display_num_errors=True)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in validate
num_errors = get_validation_errors(s, app)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/user/name/virtualenvironment/apps/proname/proname/apps/zinnia/models/__init__.py", line 19, in <module>
moderator.register(Entry, EntryCommentModerator)
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/contrib/comments/moderation.py", line 305, in register
raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.module_name)
django.contrib.comments.moderation.AlreadyModerated: The model 'entry' is already being moderated
django version -- 1.5.3
So why it is displaying AlreadyModerated error when trying to update the zinnia witj latest version ?
Issue Two
Below are my specs/setings
settings.py
ZINNIA_ENTRY_BASE_MODEL = 'proname.apps.app_name.models.EntryBase'
ZINNIA_SAVE_PING_DIRECTORIES = False
ZINNIA_PING_EXTERNAL_URLS = False
Actually i am trying to extend the Entry model as below
from zinnia.models_bases.entry import AbstractEntry
class EntryBase(AbstractEntry):
pass
class Meta(AbstractEntry.Meta):
abstract = True
verbose_name_plural = _("Entry")
verbose_name_plural = _("Entries")
def __unicode__(self):
return u'Entry %s' % self.title
django version -- 1.4.5
When i used above django version i am getting an extra error along with above one
raise ImproperlyConfigured('%s cannot be imported' % model_path)
django.core.exceptions.ImproperlyConfigured: zinnia.models_bases.entry.AbstractEntry cannot be imported
So can anyone please let me know to solve the above issues like
AlreadyModerated when updating to latest github zinnia code
Trying to extend the Entry model ?
and made the zinnia work correctly ?
I had the same problem and I figure out the problem changing version of zinnia to 0.14.3
Zinnia 0.15 only works with django 1.7
Use v0.14.3 instead.
(https://github.com/Fantomas42/django-blog-zinnia/issues/388)
I came across this issue too. The way I was able to fix it was to link back to the model_bases folder in the original zinnia package. In my site's 'zinnia' folder (where the updated South migrations are stored):
$ ln -sf <python-path>/lib/python2.7/site-packages/zinnia/models_bases .

How to setup MongoDB with Django

I've followed numerous tutorials on how to setup a Django project with MongoDB but still get the same errors when running the command for testing:
python manage.py runsever
Here is the link I've been following:
http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released
Here are the errors I get from the above command:
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10d266210>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "build/bdist.macosx-10.8-intel/egg/django_mongodb_engine/__init__.py", line 13, in <module>
AttributeError: 'tuple' object has no attribute 'insert'
I have no idea why this isn't working and ideally I just want a database setup to use specifically for storing JSON documents. Is there an easier alternative to connecting Django with another database that is ideal for storing JSON information?
For clarification:
INSTALLED_APPS should be tuple.
He gets AttributeError: 'tuple' object has no attribute 'insert' because mongodb does not handle tuple INSTALLED_APPS correctly. The default in mongodb is insert list. This is already fix before but now it's gone.
There suggestion are:
changing your settings.INSTALLED_APPS to a list instead of a tuple. (which is bad for me)
correct their code by adding the patch
There is a new package called djongo for fully nosql support with mongoDB:
- https://nesdis.github.io/djongo/
you cann install ist in your venv:
pip install djongo

Categories

Resources