Nico
The problem is not with django, but with your mysql setup https://dev.mysql.com/doc/refman/8.0/en/gone-away.html One of the ways to solve it is to increase connection timeout in mysql configs
Thanks, but wouldn't increasing connection timeout just pospose the problem? The Django command is meant to be running forever. Plus, if as per the documentation, connection is closed after each statement, why does it reach timeout there?
Alex
Thanks, but wouldn't increasing connection timeout just pospose the problem? The Django command is meant to be running forever. Plus, if as per the documentation, connection is closed after each statement, why does it reach timeout there?
> but wouldn't increasing connection timeout just pospose the problem tbh, I canno't say certenly. If you are using tcp or unix socket connection, those protocols are intended to create long living socket connections, as far as I know. > Plus, if as per the documentation, connection is closed after each statement Are you sure you are not missing connections with transactions?Django uses autocommit mode by default, yes. > default value is 0, preserving the historical behavior of closing the database connection at the end of each request Yes, but you said that the problem occurs during background task. As far as I understand, there are no http client-server request to those process, right? > I've also tried setting it to None and the result is the same. None means don't close from your side. But mysql server still can close the connection by its side.
Alex
Thanks, but wouldn't increasing connection timeout just pospose the problem? The Django command is meant to be running forever. Plus, if as per the documentation, connection is closed after each statement, why does it reach timeout there?
Or... you could manually close the connection in the task by your side https://stackoverflow.com/q/20058589/2516502 In [2]: Model.objects.count() Out[2]: 428674 In [3]: from django.db import connection In [4]: connection.close() In [5]: MOdel.objects.count() Out[5]: 428674
Alex
So django will automatically reopen it the next time you will need it.
Alex
I've tried a similar thing: from django.db import close_old_connections close_old_connections(), but I guess it's not the same. I'll give it a try. Thanks!
close_old_connections closes connections only in certain cases https://github.com/django/django/blob/main/django/db/__init__.py#L36 https://github.com/django/django/blob/main/django/db/backends/base/base.py#L502 I guess it might be a bit simpler - you just need to set CONN_MAX_AGE to a proper value which corresponds to mysql's connection timeout. So django will check that before making a query and recreate if needed. https://github.com/django/django/blob/ca9872905559026af82000e46cde6f7dedc897b6/django/db/backends/base/base.py#L185-L205
Alex
Or you could create and emit your own signals for that. I don't have an instance of mysql to check that out. So it's just a hypothesis.
Nico
Or you could create and emit your own signals for that. I don't have an instance of mysql to check that out. So it's just a hypothesis.
even if you don't have an instance of mysql thanks for the help, it's clear I'll need to twinkle the MySQL server settings to check if it's coherent with what's happening. I'll also check for a proper value for CONN_MAX_AGE. It's been hard to debug since the exception occurs each time after cca. 24 hours, so it's a change each time, but I hope I'll figure it out
Beekaaash
<link rel="stylesheet" href="{% static 'style.css' %}" type="text/css">
Style.css file inside of static folder or inside of static/css/.... Like this
Vxvek
I have a dict inside list in that there some none values how can I remove that I tired lot !! :(
P
I am fetching realtime data through python however it is getting fetched very slow , bandwidth I am getting 5mbps. So how can I use realtime data through Django?
Harish
I'm having two models A & B. B was created to normalize A. A has large number of fields (28 excluding other extra fields). I want to copy all values of these fields to B through data migration & remove them from A. I used list comprehension to first create unsaved B instances from A for those fields & used "bulk create" with the resultant list for creation. Is there any other way without using for loop to create those objects?
Брат
Hi! Somebody can explain why we need serializers? Kind of tough to understand in documentation.
Coders Needed Eth
Hi! Somebody can explain why we need serializers? Kind of tough to understand in documentation.
You use it to basically defiane your model attributes for your response exclude fields and handle certain conditions
Coders Needed Eth
I think you mean in DRF
Брат
Now I got it, I appreciate your responses!
Anonymous
Hi
Anonymous
/
ѕнυĸυralι
Is there an avtosave in a sublimetext
Pragati singh
STATIC_URL = '/static/' hi, does this line of code mean we can open any static file(image) in new tab ? or i'm wrong
Anonymous
this line collects your static files in one folder in server
Sanji
It specifies the base Url for all your static files
Pragati singh
It specifies the base Url for all your static files
so why does it have // before and after
Pragati singh
It specifies the base Url for all your static files
so, is STATIC_ROOT = os.path.join(BASE_DIR, 'static') is different ?
Anonymous
the path should be like this “yourproject/static/css/“
Anonymous
so, is STATIC_ROOT = os.path.join(BASE_DIR, 'static') is different ?
you will you “static_root” in any kind of server
Sanji
static Url just appends this url to the base url
Sanji
It may be the localhost or another
MohammadMahdi
Hi How can i prevent to access to Media directories by front?
Anonymous
Hello Everyone here I am just added to this group so thanks admin I have a question
Anonymous
Please can anyone tell me differencies between library and framework? I am just confusing
yusof
Please can anyone tell me differencies between library and framework? I am just confusing
https://stackoverflow.com/questions/148747/what-is-the-difference-between-a-framework-and-a-library#:~:text=A%20library%20performs%20specific%2C%20well,is%20done%20by%20the%20application.
Mai
Hello everyone , I am using Django parler to translate model in Arabic and English But it work one time only When I edit it there not appear two language only English appear
Anshul
Hey,can i use django to make a website where i can upload wallpaper and other can download it
Anonymous
cmon man, seriously consider the quality of your questions before you post them, and the answer is yes.
Azizbek Xushnazarov
Azizbek Xushnazarov
ISSUE There is a Profile model which is connected to User model with OneToOneFIeld. When I delete a User instance I want to delete the Profile of the User too.
Azizbek Xushnazarov
https://docs.djangoproject.com/en/3.2/ref/models/fields/#arguments Your probably need CASCADE
def when_user_deleted(sender, instance, **kwargs): instance.profile.delete() post_delete.connect(when_user_deleted, sender=User) I am using this simple signal to do this. But this is giving me the Annoying error: "User has no profile"
Azizbek Xushnazarov
the user i was deleting actually has a profile
Vivek
Hello guys if I include cronjobs in my django application will it affect the working of my application when the scheduled job runs? (Assuming the application is hosted on heroku) or the Job gets executed on a different thread?
Vivek
It will not
I was a bit hesitant because the job takes a few seconds to complete
Alex
It will not
Are you sure?
Alex
I was a bit hesitant because the job takes a few seconds to complete
You were hesitating for good. You actually DO can mess with your app by background tasks.
Alex
Even if they work in a separate process.
Alex
So is there any way to avoid issues?
Here we step in the field of knowledge called "concurrent programming". The biggest problem here is whether you have, so called, shared resources - anything you share with other process. Like memory or DB. Or maybe cache or smth else
Abdalwhab
Hi I have a question What is the average price in your country for a Django back-end Developer?
Abdalwhab
Or average salary
Alex
Yes, the job is supposed to dump data in the database which the application uses
It's really hard to recommend you a single article for you could just read it and then just go. Concurrent programming is a difficult theme. In your case, if it's only DB, you could manage concurrent conditions, if there are any, with DB transactions. Here is one of my favorite articles https://hakibenita.com/how-to-manage-concurrency-in-django-models
Alex
It actually doesn't mean that you have to learn the entire theme and use tons of locks and etc. But at least you should be warned that you DO can mess up you app in tasks.
Mahmood
I have a django project which using opencv-python Library When i tried to publish it to cpanel shared hosting, i had a problem on the opencv-python library, it couldn't build in the cpanel os So what i tried to do is build it manually in my local pc as 'whl' library, then install it in the cpanel It installed successfully but didn't work because of the 'Gun libc' version My local pc Gun libc version is 2.30, and the cpanel is 2.20 And because i build it in my pc it's built by the 2.3 gunlibc version Anybody know how to solve this problem, or anyway to install opencv-python on the cpanel os?!
Alex
use pastebin services for codesharing, pls
Bahodir
i cant save in model user_name_id automotically with authenticated user
Bahodir
friends i have to save id of the user without selecting it
Bahodir
https://dpaste.org/ynXr
Nayan
Hi i want to upload huge file to server using django , the single file size can be max 1gb please anyone can help me on this ?
Rohan
Have you tried? Are you facing any problem with that?
Ofc he’ll face problems with that. The API will hangup or show timeout
Alex
Ofc he’ll face problems with that. The API will hangup or show timeout
and not only that - he may run out of memory, depending on his setup. But I asked him what he has done till now
Alex
I'm not going to play spanish inquisition with you and torture out answers - post your code (on paste services!!!!) and provide an error message if there is one.