django_neomodel 找不到属性 MAX_POOL_SIZE
django_neomodel can't find attribute MAX_POOL_SIZE
我正在尝试设置我的第一个 Django 项目,使用 neo4j 作为数据库,使用 neomodel 作为 OGM,所以我正在关注 this directions。然而,当尝试启动 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',
]
使用以下命令从 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
我 运行 遇到了同样的问题,但我仍然不太清楚为什么会这样。 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 它 应该 提供正确的值 except为我工作。 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])
如果默认设置为对象或模块不存在的属性,则 getattr 会立即抛出 AttributeError,即使对象和名称值有效,否则 return 一个值。
看来这是 django-neomodel 代码中的错误?它期望在 neomodel 配置中设置 MAX_CONNECTION_POOL_SIZE 但事实并非如此,至少从 2021 年 1 月 22 日开始使用 neomodel 4.0.1 和 django-neomodel 0.0.4 。
我正在尝试设置我的第一个 Django 项目,使用 neo4j 作为数据库,使用 neomodel 作为 OGM,所以我正在关注 this directions。然而,当尝试启动 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',
]
使用以下命令从 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
我 运行 遇到了同样的问题,但我仍然不太清楚为什么会这样。 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 它 应该 提供正确的值 except为我工作。 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])
如果默认设置为对象或模块不存在的属性,则 getattr 会立即抛出 AttributeError,即使对象和名称值有效,否则 return 一个值。
看来这是 django-neomodel 代码中的错误?它期望在 neomodel 配置中设置 MAX_CONNECTION_POOL_SIZE 但事实并非如此,至少从 2021 年 1 月 22 日开始使用 neomodel 4.0.1 和 django-neomodel 0.0.4 。