After upgrading to Wagtail 2.15 (or 2.15.1) from 2.14.2 my production website with postgres and database search breaks and commands that are run with manage.py give an error despite me adding the required WAGTAILSEARCH_BACKENDS to settings.
I have two web apps with separate settings running from the same Wagtail version. One of the apps (putkeep) has a search bar and the other (secretgifter) does not. After upgrading Wagtail from 2.14.2 to 2.15, putkeep gives a 404 error but secretgifter does not. If I use pip to switch back to 2.14.2, then the 404 error goes away and the site loads (although results from a search give a 500 error).
If I run makemigrations (or any other command that uses manage.py) for secretgifter it works fine. For putkeep (with the search) it gives the following error:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/apps.py", line 21, in ready
set_weights()
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/backends/database/postgres/weights.py", line 44, in set_weights
BOOSTS_WEIGHTS.extend(determine_boosts_weights())
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/backends/database/postgres/weights.py", line 32, in determine_boosts_weights
boosts = get_boosts()
File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/backends/database/postgres/weights.py", line 26, in get_boosts
boosts.add(boost)
TypeError: unhashable type: 'list'
As per the docs I've added this to my settings:
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.search.backends.database',
}
}
Any suggestions gratefully received.
I have identified some code in my models.py that caused no errors with my site running Wagtail 2.14.2 and below. When commented out, it resolves the error caused by upgrading to Wagtail 2.15 and above. I am posting it here as the answer to my problem because everything else seems to work (including search) without any further modification even though I am not currently sure why it causes the error or if I need it anymore:
search_fields = Page.search_fields + [ # Inherit search_fields from Page
index.SearchField('content'),
index.SearchField('tags', [
index.SearchField('name', partial_match=True, boost=10),
]),
]
I think the issue is with your configuration that is trying to search tag names:
index.SearchField('tags', [
index.SearchField('name', partial_match=True, boost=10),
]),
The default database search doesn't appear to offer an option to search related objects this way (See note under https://docs.wagtail.io/en/stable/topics/search/indexing.html#indexing-callables-and-other-attributes). You can either remove those lines or, for the moment, go back to the postgres_search backend in wagtail/contrib.
Related
I'm upgrading a django app from v1.3 to 1.11.18.
We are running Python v2.7.12 and running an nginx server to serve the pages.
I've been making code changes to account for all of the deprecated methods as a result of the upgrade. So far, so good. After making another run of updates, I ran into this error notice after starting the server:
File "/home/bat/application.com/wsgi.py", line 12, in <module>
application = get_wsgi_application()
File "./django/core/wsgi.py", line 14, in get_wsgi_application
return WSGIHandler()
File "./django/core/handlers/wsgi.py", line 151, in __init__
self.load_middleware()
File "./django/core/handlers/base.py", line 56, in load_middleware
mw_class = import_string(middleware_path)
File "./django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "./django/middleware/locale.py", line 4, in <module>
from django.conf.urls.i18n import is_language_prefix_patterns_used
File "./django/conf/urls/i18n.py", line 2, in <module>
from django.conf.urls import url
ImportError: cannot import name url
I'm not sure why I would be getting this error as the code referenced is all core code. It doesn't appear to be referencing any of the project code at all, except for the opening line.
I've double-checked to be sure we do not have any "left over" code sitting in the core django folder: it's clean. We also rebooted the linux server just for kicks: that didn't help either. Beyond that I'm not really sure what else to try?
Any ideas where I might look for a solution to this one?
So it turns out that the ./django/conf/urls/__init__.py file is actually MISSING the required def url() function. I'm not sure how that didn't get noticed before by anyone, as the core code clearly calls that url function all over the place.
To resolve that issue, I downloaded Django v1.10.x and copied the def url(...) function from the v1.10.x code into the django/conf/urls/__init__.py file and everything worked as expected.
I do realize that I modified a core file, but I wasn't sure how to get around the issue otherwise. This 1.x branch of Django is not under active development, so I figure that's probably okay.
Hello fellow programmers, I´m following the steps to install django-fluent-contents
from the link
https://django-fluent-contents.readthedocs.io/en/latest/ quickstart.html
1- pip install django-fluent-contents
2- Basic setup
Next, create a project which uses the module. The basic module can be installed and optional plugins can be added:
INSTALLED_APPS += (
'fluent_contents',
'django_wysiwyg',
# And optionally add the desired plugins:
'fluent_contents.plugins.text', # requires django-wysiwyg
'fluent_contents.plugins.code', # requires pygments
'fluent_contents.plugins.gist',
'fluent_contents.plugins.googledocsviewer',
'fluent_contents.plugins.iframe',
'fluent_contents.plugins.markup',
'fluent_contents.plugins.rawhtml',
)
3- pip install django-fluent-contents[text,code]
4- then running python manage.py migrate
and then, error message:
D:\projetos\fluent\fluentdemo>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 381, in RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
I´ve tried with and without virtual enviroment activated, same error message!!
.......then I followed the advice of #solarissmoke, adding the django.contrib.site to INSTALLED_APPS .... but now the error message is like this:
"D:\projetos\fluent\fluentdemo\fluentdemo\veenv\lib\site-packages\fluent_contents\plugins\markup\models.py", line 10, in <module>
from fluent_contents.plugins.markup import appsettings, backend
File "D:\projetos\fluent\fluentdemo\fluentdemo\veenv\lib\site-packages\fluent_contents\plugins\markup\appsettings.py", line 34, in <module>
raise ImproperlyConfigured("The '{0}' package is required to use the '{1}' language for the '{2}' plugin.".format(backendapp, language, 'markup'))
django.core.exceptions.ImproperlyConfigured: The 'docutils' package is required to use the 'restructuredtext' language for the 'markup' plugin.
It doesn't seem to be mentioned in the documentation, but this app requires django.contrib.sites to be installed, and you're getting an error because it isn't.
Try adding django.contrib.sites to your INSTALLED_APPS.
I've got a couple of Django projects that I work on, and I use Jenkins for continuous integration purposes. I've had that arrangement up and running for a while and it works well.
I'd like to be able to generate automated test coverage reports and have Jenkins handle them as well. It looked to me like django-jenkins was the way to go for that, so I installed it and coverage.
Here's the relevant sections of my settings.py:
# Jenkins integration
INSTALLED_APPS += ('django_jenkins',)
JENKINS_TASKS = (
'django_jenkins.tasks.with_coverage',
'django_jenkins.tasks.run_pylint',
'django_jenkins.tasks.django_tests',
)
PROJECT_APPS = ['myapp']
Now, I can run python manage.py jtest, and it works as expected. However, if I run python manage.py jenkins, it errors:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 76, in load_command_class
return module.Command()
File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django_jenkins/management/commands/__init__.py", line 61, in __init__
for module_name in self.get_task_list()]
File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named django_tests
I'm using the standard Django TestCase and LiveServerTestCase classes as the basis of my tests. Any idea where I'm going wrong here? The documentation seems to imply django_tests has been removed, but I can't find any indication as to how you run the Django tests now.
I'm using Django 1.6.2.
Just realised I've been a bit of a numpty. All I needed to do was drop the django_tests line, like this:
# Jenkins integration
INSTALLED_APPS += ('django_jenkins',)
JENKINS_TASKS = (
'django_jenkins.tasks.with_coverage',
'django_jenkins.tasks.run_pylint',
)
PROJECT_APPS = ['myapp']
And django-jenkins will run the tests without having to explicitly request that it does so.
There is a change in the latest version of django_jenkins (0.18.0) so that the django_jenkins.tasks.with_coverage Jenkins Task is also no longer needed.
Instead, you execute the test run as follows:
python manage.py jenkins --enable-coverage
or
python3 manage.py jenkins --enable-coverage
You can find out more on the project's GitHub Repo.
I'm working on a new django project and following this tutorial. I'm at the step "Using South for Database Migrations", attempting to run python manage.py syncdb, and I'm getting the following error:
(editorial)[hookedonwinter#hookedonwinter editorial (master *)]$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/management/commands/__init__.py", line 13, in <module>
from south.management.commands.syncdb import Command as SyncCommand
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/management/commands/syncdb.py", line 18, in <module>
from south import migration
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/migration/__init__.py", line 11, in <module>
from south.models import MigrationHistory
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/models.py", line 4, in <module>
class MigrationHistory(models.Model):
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/db/models/base.py", line 97, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
TypeError: Error when calling the metaclass bases
__init__() keywords must be strings
Here is my settings.py file: https://gist.github.com/pjhoberman/5273653
There are no apps yet, just an empty project. I'm guessing it's a simple overlook on my part - any thoughts?
Edit
From the comments:
I don't have any models yet. Just following that tutorial, I'm trying to start with South before I do any model work.
Versions:
Django==1.5.1
South==0.7.6
If I comment out south in settings.py, I get this error:
$ python manage.py syncdb
TypeError: Error when calling the metaclass bases __init__() keywords must be strings
Edit2
I started over and used django 1.4, and it works.
Edit3
I updated python to 2.7 and used django 1.5, and it all works as well.
The "TypeError" at the bottom is the solution. You get this error from Django 1.5 if you use a Python version lower than 2.6.5. There is a Django bug report and a SO discussion on the issue. Arguably the error message is less than intuitive.
The OP is right, none of the answers solved this problem. The solutions are: 1) upgrade Python to 2.7, 2) downgrade Django to 1.4.
I think the problem is with that "~" character you have on your database setting. Try putting #coding=utf-8 as the first or second line of your settings and see what happen.
If that doesn't resolve your problem, change the database filename for one on the same directory of manage.py file like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'databasename.sql',
}
}
I tried making a new environment following that tutorial you post and i have no problem. But when i tried to use a database name as you were trying (the one with "~" in its name) i get this error:
(env) user#pc:/path >$ python manage.py syncdb --noinput
Syncing...
OperationalError: unable to open database file
I bet that symbol is the root of your problem... Tell us if this solved your problem!
I updated python to 2.7 and used django 1.5, and it all works as well.
None of the answers actually solved the problem, so I'm answering it myself since I can't delete the question now that there's bounty.
South is very well documented and i'm sure you'll be clear after going through it.
This is the tutorial.
http://south.readthedocs.org/en/0.7.6/tutorial/part1.html
Still to make life simpler..
1) Download south and add it to your apps directory.
2) Add 'south' to INSTALLED APPS in settings.py
3) Run syncdb
4) $ ./manage.py schemamigration appname --initial
5) $ ./manage.py migrate appname
This is all you need for a very basic start.
It seems a DB config problem, try this. On the top of the file:
import os
then:
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'),
}
}
And finally a syncdb should do the trick. Also you can try "python manage.py reset south" to fix possible problems in the APP. If this doesn't work i suggest you start a new problem to discard other errors.
Original post: Django setup with sqlite3?
You need Python 2.6.5+ to run Django 1.5. That's why downgrading to Django 1.4 or upgrading to Python 2.7 was what solved your problem.
https://docs.djangoproject.com/en/dev/releases/1.5/#python-compatibility
I'm running ubuntu 9.04 32b and got django from Synaptics.
My settings.py is configured for a sqlite3 database.
I've been through this tutorial and got the following error when trying to run the command python manage.py syncdb :
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 340, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 219, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 348, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 51, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 56, in cursor
cursor = self._cursor(settings)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py", line 145, in _cursor
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
Do anyone have a clue on my problem ?
In settings.py are you using a relative path to the sqlite file?
If you are, try changing that to an absolute path.
i.e. instead of:
~/project/mydata.db
use
/home/user/project/mydata.db
This can also happen if your database name is the same as your project name. To fix it just change the name of your db e.g. by adding a .db to the NAME. So if your DATABASE NAME in settings.py was 'epic_project' change it to 'epic_project.db'
Long and boring explanation:
If you start your project by running:
django startproject epic_project
your folder structure will be like this:
/path/to/epic_project/
manage.py
epic_project/
settings.py
if then in your settings.py you set your database as:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'epic_project',
...
}
}
when
python manage.py syncdb
runs it tries to open or create a sqlite db file at /path/to/epic_project/epic_project, but there is a directory there, so it says "oh ok the path exists already, let's open it as an sqlite db", unfortunately for sqlite it's a directory and not a DB, so it cries and django presents these tears to you as "sqlite3.OperationalError: unable to open database file"
might be a permission problem, does your user have sufficient right to write on the folder? for example if you do
sudo python manage.py syncdb
instead, does it work?
For Google's sake:
The path to the database must be the full path to the file --- not just the directory where the file lives.
I had the same problem on Windows then realized that syncdb would not create the specified folder if it didn't already exist. I had specified c:/mysite/db/sqlite3.db in settings but the /db/ folder didn't exist. Created it in terminal then re-ran syncdb successfully.
I had the same problem two days ago. I solved it by setting the 'NAME' in the DATABASE dictionary (settings.py) to the absolute path.
For example.
settings.py
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.sqlite3',
'NAME' : DATABASE_PATH,
}
}
here you can set the DATABASE_PATH at the top of the settings.py as such
(Not sure if this will work for windows)
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir))
DATABASE_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'your-database-name'))
For Windows you might have to use the replace method. (Not sure .. But you can try it out as follows)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir).replace('\\', '/'))
Same goes for the DATABASE_PATH.
PS. Correct me if I am wrong.
Similar to answer from user104264 - different perspective...
Currently following the YouTube tutorial I had the same error. Seems to me while running the manage.py in a virtualenv django project directory ...path to virtual env.../django_project/, the database name inside /myapp/settings.py was simply 'storage.db' so
(django-v)...path to virtual env project.../django_project/>python manage.py syncdb
created ...path to virtual env project.../django_project/storage.db
-Bill
If you are specifying a full path to db file and are still having issues, try putting an r before the string.
ie.
r'C:\home\usr\mysite\sqlite3.db'
The problem I was running into was a bootstrapping issue where some model lookups were being done at import (outside of any class or function). Per the docs, this is a bad idea.