Search code examples
pythonpython-3.xdjangoneo4jneomodel

django_neomodel can't find attribute MAX_POOL_SIZE


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/[email protected]/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/[email protected]/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',
]

Solution

  • 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 .