About the 'experimental' of 'Changed in version 1.4: Index key for glossary term should be considered experimental' - python-sphinx

question
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html
About the 'experimental' of 'Changed in version 1.4: Index key for glossary term should be considered experimental.'
What puts index key on 'experimental'?
confirmed
Editing glossary with index key, 'make clean' was needed before 'make html'. Or, the index key disappeared from genindex.html.
I guess that all of the follwing testcase shuold be passed. the first testcase is related with 'make clean'. They are passed at all, on a new indexer.
#!/usr/bin/python
import unittest
from sphinx.environment.adapters.indexentries import IndexEntries
testcase01i = {
'doc1': [
('single', 'aaa', 'id-111', '', 'clf1'),
('single', 'bbb', 'id-112', '', None),
],
'doc2': [
('single', 'aaa', 'id-121', '', None),
('single', 'bbb', 'id-122', '', 'clf2'),
], }
testcase01o = [
('clf1',
[('aaa', [[('', 'doc1.html#id-111'), ('', 'doc2.html#id-121')], [], 'clf1']), ]
),
('clf2',
[('bbb', [[('', 'doc1.html#id-112'), ('', 'doc2.html#id-122')], [], None]), ]
),
]
testcase02i = {
'doc1': [
('see','hogehoge; foo','id-211','main',None),
('seealso','hogehoge; bar','id-212','main',None), ]
}
testcase02o = [
('H',
[('hogehoge',
[[],
[('see also bar', []), ('see foo', [])],
None
])
])
]
testcase03i = {
'doc1': [
('single','func1() (aaa module)','id-311','',None),
('single','func1() (bbb module)','id-312','',None),
('single','func1() (ccc module)','id-313','',None),]
}
testcase03o = [
('F',
[('func1()',
[[],
[('(aaa module)', [('', 'doc1.html#id-311')]),
('(bbb module)', [('', 'doc1.html#id-312')]),
('(ccc module)', [('', 'doc1.html#id-313')])
],
None])])
]
testcase04i = {
'doc1': [
('single','func1() (aaa module)','id-411','',None),
('single','func1() (bbb module)','id-412','',None),
('single','func1() (ccc module)','id-413','main',None), ]
}
testcase04o = [
('F',
[('func1()',
[[],
[('(aaa module)', [('', 'doc1.html#id-411')]),
('(bbb module)', [('', 'doc1.html#id-412')]),
('(ccc module)', [('main', 'doc1.html#id-413')]), ],
None])])
]
#-------------------------------------------------------------------
class _domain(object):
def __init__(self, entries):
self.entries = entries
class _env(object):
def __init__(self, domain):
self.domain = {}
self.domain['index'] = domain
def get_domain(self, domain_type):
return self.domain[domain_type]
class _builder(object):
def get_relative_uri(self, uri_type, file_name):
return f'{file_name}.html'
#-------------------------------------------------------------------
bld = _builder()
class TestcaseIndexEntries(unittest.TestCase):
def test01_classifier(self):
self.maxDiff = None
dmn = _domain(testcase01i)
env = _env(dmn)
gidx = IndexEntries(env).create_index(bld)
self.assertEqual(testcase01o, gidx)
def test02_see_and_seealso(self):
self.maxDiff = None
dmn = _domain(testcase02i)
env = _env(dmn)
gidx = IndexEntries(env).create_index(bld)
self.assertEqual(testcase02o, gidx)
def test03_homonymous_function(self):
self.maxDiff = None
dmn = _domain(testcase03i)
env = _env(dmn)
gidx = IndexEntries(env).create_index(bld)
self.assertEqual(testcase03o, gidx)
def test04_homonymous_function(self):
self.maxDiff = None
dmn = _domain(testcase04i)
env = _env(dmn)
gidx = IndexEntries(env).create_index(bld)
self.assertEqual(testcase04o, gidx)
#-------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()
purpose
I want to know which there is some other puting index key on 'experimental'. If there is it, I want to see if it is fixed by the indexer.
note
I am writing this using a translation software. If there is anything difficult to understand, I will add it.

Related

zappa wagtail how to use s3 for media/images (server error 500)

Im using wagtail on an aws lambda with zappa.
Everything is working fine except the images i'm trying to upload in the blog posts.
That is to say when i try to upload an image in the /cms-admin in the images menu i get a server error 500 message.
I have configured the images to be stored on s3 following this post https://wagtail.org/blog/amazon-s3-for-media-files/ but it seems there is a problem.
Here is my models.py :
from django.db import models
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.snippets.models import register_snippet
from taggit.models import Tag as TaggitTag
from modelcluster.fields import ParentalKey
from taggit.models import TaggedItemBase
from modelcluster.tags import ClusterTaggableManager
from wagtail.admin.edit_handlers import (FieldPanel,
FieldRowPanel,
InlinePanel,
MultiFieldPanel,
PageChooserPanel,
StreamFieldPanel,
)
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.core.fields import StreamField
from .blocks import BodyBlock
class BlogPage(Page):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [FieldPanel("description", classname="full")]
class PostPage(Page):
header_image = models.ForeignKey(
"wagtailimages.Image", null=True,
blank=True, on_delete=models.SET_NULL, related_name="+",)
body = StreamField(BodyBlock(), blank=True)
tags = ClusterTaggableManager(through="blog.PostPageTag", blank=True)
content_panels = Page.content_panels + [ ImageChooserPanel("header_image"), InlinePanel("categories", label="category"), FieldPanel("tags"),StreamFieldPanel("body"),]
#register_snippet
class BlogCategory(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=80)
panels = [ FieldPanel("name"),
FieldPanel("slug"),]
def __str__(self):
return self.name
class Meta:
verbose_name = "Category"
verbose_name_plural = "Categories"
#register_snippet
class Tag(TaggitTag):
class Meta:
proxy = True
class PostPageBlogCategory(models.Model):
page = ParentalKey("blog.PostPage", on_delete=models.CASCADE, related_name="categories" )
blog_category = models.ForeignKey("blog.BlogCategory", on_delete=models.CASCADE, related_name="post_pages")
panels = [ SnippetChooserPanel("blog_category"),]
class Meta:
unique_together = ("page", "blog_category")
class PostPageTag(TaggedItemBase):
content_object = ParentalKey("PostPage", related_name="post_tags")
Here is my settings.py
"""
Django settings for react_wagtail_app project.
Generated by 'django-admin startproject' using Django 4.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-jvstu05lh1fp2ow26blj&5%x_7bb(e*qt#(urj+$(2n&1i&)ka'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['xwovkgc3f6.execute-api.eu-west-3.amazonaws.com']
# Application definition
INSTALLED_APPS = [ 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
"wagtail.snippets",
"wagtail.documents",
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail.core",
"modelcluster",
"taggit",
"blog",
"storages"]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]
ROOT_URLCONF = 'react_wagtail_app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'react_wagtail_app.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'spa',
'USER': 'postgres',
'PASSWORD': 'password',
'HOST': '146.190.238.8',
'PORT': '5432',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'fr-FR'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
AWS_STORAGE_BUCKET_NAME = "zappa-pasvx3uig"
AWS_ACCESS_KEY_ID = 'secret'
AWS_SECRET_ACCESS_KEY = 'secret'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
#MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "/dev/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
WHITENOISE_STATIC_PREFIX = "/static/"
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
#MEDIA_ROOT = str(BASE_DIR / 'media')
WAGTAIL_SITE_NAME = 'My Project'
I have seen in other posts here: Configuring Django/Wagtail media to use S3
that a special class is used inherited from S3BotoStorage. I was wondering if i didnt need to use that in my models.py for the Images?
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
Could you help me understand what is not properly configured so the images are properly uploaded to s3 and print on the screen normally
I ve tried to set AWS_DEFAULT_ACL='public-read' following another stackoverflow post but it is the same.
zappa tail gives me the following error :
botocore.exceptions.ClientError: An error occurred (InvalidToken) when calling the PutObject operation: The provided token is malformed or otherwise invalid.
I ve managed to overcome this error by providing two separate credentials
AWS_S3_ACCESS_KEY_ID
and AWS_ACCESS_KEY_ID
but i'm still having problems with the images
I'm considering giving up on aws lambda with zappa and switching to a container service
I am afraid I don't know anything about Zappa. We use ElasticContainerService running on EC2 instances we manage. We are considering going to ECS on Fargate but have not made the transition yet.
Looking at your settings file CHANGE YOUR AWS CREDENTIALS AT ONCE!!!!
After that, I am fairly sure you need the MEDIA_ROOT and MEDIA_URL settings. Ours are set to MEDIA_ROOT = '/media' and MEDIA_URL = '/media/'. And we do have AWS_DEFAULT_ACL = 'public-read' so that images can be served straight from S3 using the default for WAGTAILDOCS_SERVE_METHOD of 'redirect'
Until you get s3 storage working, I would remove the AWS_S3_CUSTOM_DOMAIN setting so you can debug one thing at a time.

How can Jenkins job UI be updated when a new parameter added dynamically by groovy?

I am trying to use Active choices parameter to implement dropdown elements in Jenkins UI. Although I figured it out how to add a new active choice parameter, the new parameter only shows up in the page when I refresh the page. I could not find a way to refresh page or any other jenkins job method to do that for me. Can you at least tell me if that is possible, even better, an alternative way to realize what I am tring to achive?
def Parameters = []
Parameters.add([$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select type',
filterLength: 1,
name: 'TYPE',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Script Error\']'
],
script: [
classpath: [],
sandbox: false,
script:
'''
return["Select type","type1","type2"]
'''
]
]
])
Parameters.add([$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select an environment',
filterLength: 1,
name: 'ENVIRONMENT',
referencedParameters: 'TYPE',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'''
return["Script Error"]
'''
],
script: [
classpath: [],
sandbox: false,
script:
'''
import hudson.model.ParameterDefinition
import hudson.model.StringParameterDefinition
import hudson.model.ParametersDefinitionProperty
import org.biouno.unochoice.ChoiceParameter
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.biouno.unochoice.CascadeChoiceParameter;
import org.apache.commons.lang.StringUtils;
import org.biouno.unochoice.ChoiceParameter;
import org.biouno.unochoice.model.GroovyScript;
import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.scriptsecurity.scripts.languages.GroovyLanguage;
def job = jenkins.model.Jenkins.instance.getItemByFullName('deneme2')
def paramDefProp = job.getProperty(ParametersDefinitionProperty.class);
def newParameters = new ArrayList<ParameterDefinition>();
newParameters += paramDefProp.getParameterDefinitions();
if(TYPE == "type1"){
def SCRIPT = 'return (1..99).collect{String.format("%02d",it)}';
def FALLBACK_SCRIPT = 'return["Script Error"]';
GroovyScript script = new GroovyScript(new SecureGroovyScript(SCRIPT, Boolean.FALSE, null), new SecureGroovyScript(FALLBACK_SCRIPT, Boolean. FALSE, null));
newParameters.add(new ChoiceParameter("ID", "Choose ID", "randomName", script, "", true, 0))
job.removeProperty(paramDefProp)
job.addProperty(new ParametersDefinitionProperty(newParameters));
}
return["Select an environment","env1","env2"]
'''
]
]
])
properties([parameters(Parameters)])
pipeline {
agent any
stages {
stage('stage') {
steps {
script{
println "fake print"
}
}
}
}
}

How can add "templates " and "statics" folder in Django 3.1

setting.py
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
#TEMPLATES_DIR = path.join(BASE_DIR, 'templates') #it dosen't work
#STATICS_DIR = path.join(BASE_DIR, 'statics') #it also dosen't work
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0#nf#$8nm5jb0)meuq&j6kztt534#nhk)k&$zh=#emcxi7_7fo'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicianapp',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'musicianList.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATES_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'musicianList.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
STATICS_DIR,
]
Please consern on the top and 3rd top line where is the main difference from Djago2.7 version
In Djnago2.7 where imported os as below,
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
and I used the below code for connecting templates and statics forlder
TEMPLATES_DIR =os.path.join(BASE_DIR,"templates")
STATICS_DIR =os.path.join(BASE_DIR,"statics")
But there is differece in form Djnago 3.1 from pathlib imported Path given below,
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
and the os techinques dosen't works as below
TEMPLATES_DIR =os.path.join(BASE_DIR,"templates")
STATICS_DIR =os.path.join(BASE_DIR,"statics")
How can I make connection with templates and statics folder, need help.
Note: I create templates and statics folders in main projects where already presented manage.py and db.sqlite3 file. below the screenshot of my projects direction,
If you look at the top of the settings.py file, you'll see BASE_DIR is using pathlib:
BASE_DIR = Path(__file__).resolve().parent.parent
Because of this, you no longer need os to join the paths, you can simply do:
STATICS_DIR = BASE_DIR / "statics"
This is new in 3.1 - you can read about it in the release notes here: https://docs.djangoproject.com/en/3.1/releases/3.1/
I would also recommend https://docs.djangoproject.com/en/4.0/howto/overriding-templates/, but if nothing happens then it should be the Refactoring problem especially when using PyCharm. So, you need to revert your changes. It worked for me.

Problem with the error * A server error occurred. Please contact the administrator * django rest framework

I am trying to test some basic backed fonctionnalities but I seem to have this error A server error occurred. Please contact the administrator while trying to connect to the localhost http://127.0.0.1:8000 or http://127.0.0.1:8000/sise/.
At first I had this error showing django.core.exceptions.ImproperlyConfigured: The included URLconf 'Dashboard_sise.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import. but After I commented this line in the settings file ROOT_URLCONF = 'Dashboard_sise.urls' the error changed into A server error occurred. Please contact the administrator.
Can anyone please help me figure this problem out, I already tried changing the urlpatterns in the urls.py files but it didn't work, I also tried manipulating the MIDDLEWARE section in the settings file but nothing changed.
This is the Dashboard_sise.urls code
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.sites.urls),
path('sise/', include('Dashboard.urls')),
]
This is the Dashboard.urls code
from rest_framework.routers import DefaultRouter
from Dashboard.views import *
router = DefaultRouter()
router.register(r'accee', AcceeViewSet, basename='accee')
router.register(r'rapport', RapportViewSet, basename='rapport')
router.register(r'prise_fonction', PointageUtilisateurViewSet, basename='prise_fonction')
urlPatterns = router.urls
and finally the settings file
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+f-#$j*(-8^*7ijk#6_hpki#)am4e%na6ttp)54#-ddcs0#fgy'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
PREPEND_WWW = False
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'Dashboard',
'frontend'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'Dashboard_sise.wsgi.application'
'''ROOT_URLCONF = 'Dashboard_sise.urls'''
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'MainCourante',
'USER': 'postgres',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
APPEND_SLASH = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
'''REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.authentification.BasicAuthentification'
'rest_framework.authentification.SessionAuthentification'
# 'rest_framework.permissions.IsAuthentificated'
# 'rest_framework.permissions.AllowAny'
)
}'''
CORS_ORIGIN_ALLOW_ALL = True # If this is used then `CORS_ORIGIN_WHITELIST` will not have any effect
Thank you in adavance
I will answer this in case someone faced the same bug. I had a problem with the database structure .. The models implemented in the models.py file and the database created didn't match so it kept showing me this error ... once I fixed the models.py file it all worked well
Maybe this was the cause.
urlPatterns = router.urls
its usually urlpatterns.

adding allowDiskUse parameter to db.collection.aggregate() query using Mongoid

I recently updated mongodb from 2.4 to 2.6, and the new memory limit in aggregate() is causing my aggregation to fail with the following error:
Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
#length=251
#request_id=6
#response_to=0
#op_code=2004
#flags=[:slave_ok]
#full_collection_name="items.$cmd"
#skip=0
#limit=-1
#selector={:aggregate=>"items", :pipeline=>[{"$group"=>{"_id"=>"$serial_number", "total"=>{"$sum"=>1}}}, {"$match"=>{"total"=>{"$gte"=>2}}}, {"$sort"=>{"total"=>-1}}, {"$limit"=>750000}]}
#fields=nil>
failed with error 16945: "exception: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in."
So, I'm trying to pass allowDiskUse: true in the query:
dupes = Item.collection.aggregate([{
'$group' => {'_id' => "$serial_number", 'total' => { "$sum" => 1 } } },
{ '$match' => { 'total' => { '$gte' => 2 } } },
{ '$sort' => {'total' => -1}},
{ '$limit' => 750000 }],
{ 'allowDiskUse' => true })
But this isnt working.... no matter how I try I get this error:
Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
#length=274
#request_id=2
#response_to=0
#op_code=2004
#flags=[:slave_ok]
#full_collection_name="items.$cmd"
#skip=0
#limit=-1
#selector={:aggregate=>"items", :pipeline=>[{"$group"=>{"_id"=>"$serial_number", "total"=>{"$sum"=>1}}}, {"$match"=>{"total"=>{"$gte"=>2}}}, {"$sort"=>{"total"=>-1}}, {"$limit"=>750000}, {"allowDiskUse"=>true}]}
#fields=nil>
failed with error 16436: "exception: Unrecognized pipeline stage name: 'allowDiskUse'"
Does anyone know how I can structure this query appropriately to pass allowDiskUse outside of the pipeline arg?
Follow below syntax for Mongoid 5.0.0
Modelname.collection.aggregate(
[your stages, ... ],
:allow_disk_use => true
)
For instance
group = { "$group" => {"_id" => {"column_xyz"=>"$column_xyz" }, "collection_name" => { "$push" => "$$ROOT" }, "count" => { "$sum" => 1 } }};
Hive.collection.aggregate([group], {:allow_disk_use => true})
ref: MongoDB jira Ruby-1041's comments
The problem is that Moped does not currently permit options for Moped::Collection#aggregate, just a pipeline for args,
as can be seen here: https://github.com/mongoid/moped/blob/master/lib/moped/collection.rb#L146 -
the Mongo Ruby driver supports options for Mongo::Collection#aggregate, but Mongoid 3 uses Moped for its driver.
However, thanks to the dynamic nature of Ruby, you can work around this.
The following test includes a monkey-patch for Moped::Collection#aggregate provided that you supply the pipeline
as an array for the first argument, allowing you to tack on options like allowDiskUse.
Hope that this helps.
test/unit/item_test.rb
require 'test_helper'
module Moped
class Collection
def aggregate(pipeline, opts = {})
database.session.command({aggregate: name, pipeline: pipeline}.merge(opts))["result"]
end
end
end
class ItemTest < ActiveSupport::TestCase
def setup
Item.delete_all
end
test "moped aggregate with allowDiskUse" do
puts "\nMongoid::VERSION:#{Mongoid::VERSION}\nMoped::VERSION:#{Moped::VERSION}"
docs = [
{serial_number: 1},
{serial_number: 2},
{serial_number: 2},
{serial_number: 3},
{serial_number: 3},
{serial_number: 3}
]
Item.create(docs)
assert_equal(docs.count, Item.count)
dups = Item.collection.aggregate(
[{'$group' => {'_id' => "$serial_number", 'total' => {"$sum" => 1}}},
{'$match' => {'total' => {'$gte' => 2}}},
{'$sort' => {'total' => -1}},
{'$limit' => 750000}],
{'allowDiskUse' => true})
p dups
end
end
$ rake test
Run options:
# Running tests:
[1/1] ItemTest#test_moped_aggregate_with_allowDiskUse
Mongoid::VERSION:3.1.6
Moped::VERSION:1.5.2
[{"_id"=>3, "total"=>3}, {"_id"=>2, "total"=>2}]
Finished tests in 0.027865s, 35.8873 tests/s, 35.8873 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

Resources