Thursday, February 3, 2022

Re: Resource leaks from FieldFile's implicit open?

Hello,

many thanks for your reply!

Am 02.02.22 um 09:17 schrieb Antonis Christofides:
> It is actually FieldFile.open() that is a wrapper around Storage.open(). Therefore I think I'd rephrase as follows:
>
> FieldFile is a subclass of File. While File is a wrapper around Python's built-in file object, FieldFile uses the underlying Storage.

Yes, thanks, that makes a lot more sense than what's in the docs!

> Inside the "with" block you will probably access `some_file_field.file`. Apparently accessing that attribute is what opens the file (but accessing the `size` attribute also seems to be opening it, which is probably suboptimal.)

Yes, and e.g. the `width` attribute if it is an image...

I had a look at the code, but there are still a *lot* of open questions. At this time, I consider to not use FileField at all but to use plain CharFields instead to just store the file names and then to use the storage directly. This removes an entire layer of abstraction without which things seem to be a lot clearer.

Best regards,
Carsten



> On 01/02/2022 21.22, Carsten Fuchs wrote:
>> Dear group,
>>
>> despite a lot of reading and searching I still don't understand how FieldFiles work.
>>
>> The documentation at https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.fields.files.FieldFile says:
>>
>>> The API of FieldFile mirrors that of File, with one key difference: The object wrapped by the class is not necessarily a wrapper around Python's built-in file object. Instead, it is a wrapper around *** the result of the Storage.open() method ***, which may be a File object, or it may be a custom storage's implementation of the File API.
>> (I added markers to indicate the portion that I have trouble with.)
>>
>> As far as I understand this, whenever a `FieldFile` is instantiated, `Storage.open()` is called. Thus, if the underlying storage is the `FileSystemStorage`, a Python file object is opened.
>>
>> However, how is this file handle closed again?
>>
>> It looks as if it stays open until garbage collected, that is, possibly for a very long time.
>>
>> Another consequence besides the potential resource leak seems to be that the implicit open will raise an exception if the file that the `FieldFile` refers to doesn't exist. As I don't exactly understand when this opening occurs, a lot of code must be wrapped in try-except blocks to handle this?
>>
>> Best regards,
>> Carsten
>>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2db4c126-10b2-a79f-fb00-bd9b836db209%40cafu.de.

Re: Static files not found

Please add this line below static_url

STATICFILES_DIRS = [
'static'
]

On Thu, Feb 3, 2022, 20:53 Serge Alard <serge.alard54@gmail.com> wrote:
Hello

I developped a project in Django python that works fine. Thus, I deployed my project. Everything works but the static files are not found by the application.
I give you below the settings and wsgi files.

WSGI
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Web_bridge.settings')

application = get_wsgi_application()

SETTINGS
import os
from pathlib import Path

os.environ['ENV'] = 'PRODUCTION'

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

DEBUG = False
SECRET_KEY = 'django-insecure-eqlug^3e20v1c5%mo9*mhhea^vv$!$&hyiz-tr%x&6!@6$+e%7'
ALLOWED_HOSTS = ['*']

STATIC_ROOT = os.path.join(BASE_DIR, "static")

INSTALLED_APPS = [
'bridge.apps.BridgeConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
]

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 = 'Web_bridge.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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 = 'Web_bridge.wsgi.application'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql', # on utilise l'adaptateur postgresql
'NAME': 'sudoku_bridge', # le nom de notre base de donnees creee precedemment
'USER': 'sudoku', # attention : remplacez par votre nom d'utilisateur
'PASSWORD': '*',
'HOST': 'postgresql-sudoku.alwaysdata.net',
'PORT': '5432',
'CONN_MAX_AGE': 500,
}
}

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

LANGUAGE_CODE = 'fr-FR'

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_L10N = True

USE_TZ = False

STATIC_URL = 'static/'

Thank you in advance to help me.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1c8bda14-d16f-405f-9c66-29e63275419bn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF7qQgD5cHEDVcoCtL6JNJQyg%3Dhqr15bskOg6RWCKKn4-YCreQ%40mail.gmail.com.

Re: Potential bug: mysql-connector-python Django 3.2.11 and third-party packages that populate the Admin Site

mysql-connector-python 8.0.27 has another bug (see  https://stackoverflow.com/questions/69900463/django-migration-error-typeerror-sequence-item-1-expected-a-bytes-like-object ) so I did not try it.

mysql-connector-python 8.0.26 did not have this problem with Django 3.1. So the bug must have been introduced in the transition to Django 3.2.

From what I am picking up (for example from Lakshyaraj Dash above), mysql-connector-python seems to be buggy generally and mysqlclient should be used as the first choice.  

On Thu, Feb 3, 2022 at 4:14 PM Jason <jjohns98684@gmail.com> wrote:
can you observe the same behavior in previous versions of connector?  You listed two patch versions, makes me curious where in the 8.x version line this works.  Likely this is an issue with mysql-connector-python, but with it being an Oracle product, it doesn't have much internal visibility.  So could be helpful to downgrade versions till you get a working one.

On Wednesday, February 2, 2022 at 9:01:51 PM UTC-5 dashlaksh...@gmail.com wrote:
Use only the mysqlclient package to populate your admin site with MySQL database.

You can watch this tutorial also : https://youtu.be/SNyCV8vOr-g

On Thu, Feb 3, 2022, 06:19 Richard Mayebo <rma...@gmail.com> wrote:
Platform: Observed on Ubuntu 20.04

  1. Install MySQL (Observed on 5.7 and 8.0)
  2. Create a Virtual environment using venv, and activate it.
  3. Install Django 3.2.11
  4. Install mysql-connector-python (Observed on 8.0.26 and 8.0.28)
  5. Install django-easy-audit and/or django-axes (both these third party packages populate the Django Admin Site, where the apparent bug manifests).
  6. Create a superuser (python manage.py createsuperuser)
  7. Start Django (python manage.py runserver)
  8. Launch the Django Admin Site and log in with the superuser.
  9. The pane on the left hand side will have links to objects created by django-easy-audit and/or django-axes, depending on what was installed.
  10. Click on the "Request event" link under "Easy Audit Application" or "Access logs" under "Axes"
  11. RESULT: 
Template error: In template /home/......../.venv/lib/python3.8/site-packages/django/contrib/admin/templates/admin/base.html, error at line 44

   'NoneType' object has no attribute 'day' [OR  'NoneType' object has no attribute 'month'] 

This behaviour is observed on MySQL 5.7.37 and 8.0.26 using my-sql-connector 8.0.26 and 8.0.28.

Replacing MySQL with SQLite or PostgreSQL 12 solves the issue. 

Replacing the connector with mysqlclient-2.1.0 solves the issue. 

This implies there is a bug in the interaction between third-party packages like django-easy-audit and django-axes, Django 3.2.11 and my-sql-connector 8.0.26 and 8.0.28.

Has similar behaviour been observed by anyone else? In any case, how can this be brought to the attention of the development team?

My apologies if this is the wrong forum for this post. I am new at this.

Regards,
Richard.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0a483673-3393-42f9-87a1-c4463c583d7dn%40googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/s1s42RcxNMQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d3eda24e-ab25-406c-9992-3af6f98701c1n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHYamgAJvB8M9b3c_Mqd8t7ZbbWMnYjjCHhF-Cvme9V%3D18E3fA%40mail.gmail.com.

Re: Potential bug: mysql-connector-python Django 3.2.11 and third-party packages that populate the Admin Site

can you observe the same behavior in previous versions of connector?  You listed two patch versions, makes me curious where in the 8.x version line this works.  Likely this is an issue with mysql-connector-python, but with it being an Oracle product, it doesn't have much internal visibility.  So could be helpful to downgrade versions till you get a working one.

On Wednesday, February 2, 2022 at 9:01:51 PM UTC-5 dashlaksh...@gmail.com wrote:
Use only the mysqlclient package to populate your admin site with MySQL database.

You can watch this tutorial also : https://youtu.be/SNyCV8vOr-g

On Thu, Feb 3, 2022, 06:19 Richard Mayebo <rma...@gmail.com> wrote:
Platform: Observed on Ubuntu 20.04

  1. Install MySQL (Observed on 5.7 and 8.0)
  2. Create a Virtual environment using venv, and activate it.
  3. Install Django 3.2.11
  4. Install mysql-connector-python (Observed on 8.0.26 and 8.0.28)
  5. Install django-easy-audit and/or django-axes (both these third party packages populate the Django Admin Site, where the apparent bug manifests).
  6. Create a superuser (python manage.py createsuperuser)
  7. Start Django (python manage.py runserver)
  8. Launch the Django Admin Site and log in with the superuser.
  9. The pane on the left hand side will have links to objects created by django-easy-audit and/or django-axes, depending on what was installed.
  10. Click on the "Request event" link under "Easy Audit Application" or "Access logs" under "Axes"
  11. RESULT: 
Template error: In template /home/......../.venv/lib/python3.8/site-packages/django/contrib/admin/templates/admin/base.html, error at line 44

   'NoneType' object has no attribute 'day' [OR  'NoneType' object has no attribute 'month'] 

This behaviour is observed on MySQL 5.7.37 and 8.0.26 using my-sql-connector 8.0.26 and 8.0.28.

Replacing MySQL with SQLite or PostgreSQL 12 solves the issue. 

Replacing the connector with mysqlclient-2.1.0 solves the issue. 

This implies there is a bug in the interaction between third-party packages like django-easy-audit and django-axes, Django 3.2.11 and my-sql-connector 8.0.26 and 8.0.28.

Has similar behaviour been observed by anyone else? In any case, how can this be brought to the attention of the development team?

My apologies if this is the wrong forum for this post. I am new at this.

Regards,
Richard.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0a483673-3393-42f9-87a1-c4463c583d7dn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d3eda24e-ab25-406c-9992-3af6f98701c1n%40googlegroups.com.

Wednesday, February 2, 2022

Re: Barcode

We implemented bar coding on the back end - e.g., to generate a PDF which the client then prints.

One library you can use for this is:
https://pypi.org/project/treepoem/


On Wednesday, 2 February 2022 at 02:05:56 UTC+2 andres....@uaiinpebi-cric.edu.co wrote:
Does anyone have experience with UCC/EAN-128 barcodes? I am using a javascript barcode js library with django to implement the barcode but it is generating errors when reading if anyone knows any library or api that can be used that complies with the UCC/EAN-128 parameters that can provide me with information

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6ea4902e-9a13-4aad-9c8a-84a217d2a991n%40googlegroups.com.

Re: Django docs failing

In the mean time, you can read same the docs here too: https://readthedocs.org/projects/django/

On Wednesday, February 2, 2022 at 10:47:55 PM UTC-6 Mike Dewhirst wrote:
The following error occurs when searching the docs for a term. It looks
like the content delivery network node in Sydney Australia has had a
certificate renewal glitch.


Error 503 certificate has expired

certificate has expired


Guru Mediation:

Details: cache-syd10147-SYD 1643862123 79021947

------------------------------------------------------------------------

Varnish cache server


--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a77e035-5132-a2a6-f34a-a69724c1a4b7%40dewhirst.com.au.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ce839dbd-5a02-4946-97c3-e6f30d359c91n%40googlegroups.com.

Re: Django docs failing with search docs - certificate has expired

I'm having the same issue starting about 10 minutes ago. For docs.djangoproject.com and code.djangoproject.com. Root domain works fine.
On Wednesday, February 2, 2022 at 11:24:45 PM UTC-5 Mike Dewhirst wrote:

Error 503 certificate has expired

certificate has expired


Guru Mediation:

Details: cache-syd10147-SYD 1643862123 79021947

------------------------------------------------------------------------

Varnish cache server


--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/98de31ae-e897-4c8f-8591-381b287c7711n%40googlegroups.com.