0

我正在尝试使用 neo4j 作为数据库和 neomodel 作为 OGM 设置我的第一个 Django 项目,所以我遵循这个方向。然而,当尝试启动 Django 服务器时,我得到了这个错误:

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'

我正在使用 python 3.7 和 Django 3.1.4。

编辑 这些是我的设置,作为指示状态,我还没有代码,我只想用这个设置启动 Django 服务器。

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',
]
4

2 回答 2

0

使用以下命令从 git下载django_neomodel包:

pip install -e git+https://github.com/neo4j-contrib/django-neomodel.git#egg=django-neomodel

由于neomodel包中的配置文件包含MAX_POOL_SIZE安装django_neomodel时的设置,pip install django_neomodel而不是MAX_CONNECTION_POOL_SIZE

于 2021-01-20T07:20:54.193 回答
0

我遇到了同样的问题,但仍然不太确定为什么会这样。neomodel-django 中的 apps.py 文件会抛出此错误消息:

 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)

看起来如果您在 django 设置文件中设置 NEOMODEL_MAX_CONNECTION_POOL 它应该提供正确的值,除非这对我不起作用。getattr (config.MAX_CONNECTION_POOL_SIZE) 中提供的默认值是 neomodel 配置对象/模块的属性,显然默认情况下没有设置。无论出于何种原因,getattr 都试图获取此默认值,但默认情况下该属性不存在。

我想如果我手动设置 config.MAX_CONNECTION_POOL_SIZE,我会看到发生了什么。好消息,它奏效了!所以,我只是将它添加到我的 settings.py 中:

from neomodel import config    
config.MAX_POOL_SIZE = 50

我承认我没有经常使用 getattr,所以我尝试了它以更好地了解它是如何工作的。这是函数定义:

 getattr(object, name[, default])

如果 default 设置为对象或模块不存在的属性,则 getattr 立即抛出 AttributeError,即使对象和名称值有效并且否则将返回值。

所以这似乎是 django-neomodel 代码中的一个错误?期望在 neomodel 配置中设置 MAX_CONNECTION_POOL_SIZE ,但情况并非如此,至少截至 21 年 1 月 22 日使用 neomodel 4.0.1 和 django-neomodel 0.0.4 。

于 2021-01-24T14:34:38.867 回答