Re: DB queries at import time
Am 12.04.2012 23:33, schrieb Matt Schinckel: If you install django-devserver, and enable SQL queries in the console, then every query will be displayed as it happens, and you should be able to track them down. thank you, django-devserver seems to have a lot of other nice debugging features. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DB queries at import time
If you install django-devserver, and enable SQL queries in the console, then every query will be displayed as it happens, and you should be able to track them down. Matt. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ELbykFSSiFwJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DB queries at import time
On Thursday, 12 April 2012 13:09:54 UTC+1, guettli wrote: > > Hi, > > sometimes it happens, that db queries get executed at import time (during > importing the file by the interpreter). > That's waste of time a resources. > Why? Imports only happen the first time a process accesses a module. A process lasts for many requests. > Is there a way to test how many queries get executing during import? I > want some automated way to detect these db queries. > > Example: > > def mychoices(): > for obj in MyModel.objects.all(): # this hits the db during import. > That's not good. > > > class MyForm(forms.Form): > foo=forms.ChoiceField(choices=mychoices()) > The problem caused by this being executed at import time is not a "waste of time and resources", but the fact that if you add objects to MyModel, they won't appear in the MyForm.foo choices, until the process is restarted - which could be several days. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/XwdAWoqNwv8J. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DB queries at import time
Am 12.04.2012 15:25, schrieb Jani Tiainen: 12.4.2012 15:09, Thomas Guettler kirjoitti: Hi, sometimes it happens, that db queries get executed at import time (during importing the file by the interpreter). That's waste of time a resources. Is there a way to test how many queries get executing during import? I want some automated way to detect these db queries. Example: def mychoices(): for obj in MyModel.objects.all(): # this hits the db during import. That's not good. class MyForm(forms.Form): foo=forms.ChoiceField(choices=mychoices()) That is because you pass parameter as a function call, so of course function must be evaluated. So in your code reads: ... Yes, I know this. But I work in a team where not everybody is a django expert. I search a way to test for queries which happen at import time. django debug toolbar does some tricky wrapping of cursor.execute(). I guess this could be a solution. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: DB queries at import time
12.4.2012 15:09, Thomas Guettler kirjoitti: Hi, sometimes it happens, that db queries get executed at import time (during importing the file by the interpreter). That's waste of time a resources. Is there a way to test how many queries get executing during import? I want some automated way to detect these db queries. Example: def mychoices(): for obj in MyModel.objects.all(): # this hits the db during import. That's not good. class MyForm(forms.Form): foo=forms.ChoiceField(choices=mychoices()) That is because you pass parameter as a function call, so of course function must be evaluated. So in your code reads: Declare class attribute "foo" as a new instance of "forms.ChoiceField" with parameter of "choices" with values returned from "mychoices". So to get rid of that part, you can pass method or a function as a parameter and it will be evaluated at the runtime: class MyForm(forms.Form): foo=forms.ChoiceField(choices=mychoices) -- Jani Tiainen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
DB queries at import time
Hi, sometimes it happens, that db queries get executed at import time (during importing the file by the interpreter). That's waste of time a resources. Is there a way to test how many queries get executing during import? I want some automated way to detect these db queries. Example: def mychoices(): for obj in MyModel.objects.all(): # this hits the db during import. That's not good. class MyForm(forms.Form): foo=forms.ChoiceField(choices=mychoices()) -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.