Django dev server slowness with chrome + other instance / browser - django

First let me say that this is not about production settings for django - it's for local development and testing.
I'm testing out multiple user scenarios, requiring I log in as several different users. I'm logged in as user A using Chrome, and user B using Chrome's incognito mode, and as user C using Firefox. I'm using "manage.py runserver" to run the dev server.
The first instance with regular Chrome (user A) works well and is fast. The other instances are very slow - perhaps better described as stuck. They sit around doing nothing for 10-30 seconds, and then finally display the page fairly quickly.
While the other browsers are stuck I can go to the first one (user A) and click around and it works well and is fast. In other words only the requests from the other two instances get stuck - the first instance always works well.
The resource that's slow appears to be the html page, not the static content.
The backend is Django 1.1.1 with SQLite as the database running on OS X 1.6.7 .
Any ideas? Is Chrome doing something special to hog the connection?

This could be a known issue "Development web server sometimes hangs with Chrome":
https://code.djangoproject.com/ticket/16099
It is fixed recenty in django trunk:
https://code.djangoproject.com/changeset/16427

Related

Django web site URLS gets "?next=" randomly after deployed to heroku

After deploying django app on heroku the url after every form submission or link in site been press resulting with "?next=" inserts into the URL address, I don't understand from where it comes and why heroku keep inserting them in a random way, running the application locally just working perfectly.
I've deleted the application from heroku and upload it again, the fault persists.
There's no http errors what so ever. If I keep submitting the form eventually will works.
For example: pressing the log button in the django admin console results with this URL: https://appname.herokuapp.com/admin/login/?next=/admin/login/admin/, hitting it quite a bit will finally make it work with the correct url display: https://mishnayot.herokuapp.com/admin/.
Switching from heroku postgres to AWS RDS postgres didn't help.
Help will be very appreciated.
When a user hits a page requiring authentication, they get redirected to the login URL with a ?next= indicating the page they were trying to access. This way, after they've logged in, they'll get the page they intended to access.
In your case, it seems like /admin/login/admin/ requires a login and the login is actually at /admin/login/. I'm guessing you have a bad link to /admin/login/admin/ somewhere when you intended to just have /admin/login/?
Well, struggling for days just to understand it's heroku backend issue and there's not enough information that could help me solving it (i did try to contact heroku support directly but I'm on a free account).
Finally I decided to deploy it using elastic beanstalk. The implementation took some time with long learning curve but now my site works and works great!
Thanks for trying to help Tim.
Cheers!

How to wait long enough for Django views results on Firefox?

I'm developing a website with Django 2.2, using :
Centos 7
Mozilla Firefox 60.6.0
Google Chrome 73.0.3683.86
Docker and Docker compose
The first page allows the user to submit data from a formatted file (equivalent to csv) and the second page shows the result of calculations (done row by row) in a datatable.
I have noticed a difference between Mozilla Firefox and Google Chrome:
For big files, on Chrome, the web browser waits long enough to receive and display the results of calculations. Whereas in Firefox, the web browser stops waiting for localhost and the "results" page is not loaded.
As the problem occured when the file exceeded a certain size, I have guessed that the app spent too much calculating time and Firefox stopped waiting for the response before to load the "results" page.
So I changed my view to accelerate calculations. The problem still persists with big files. With files from approximately 3.5Mo the results page os displayed or not (almost randomly).
I tried to raise "dom.max_script_run_time" in my Mozilla settings but this can't be done programatically.
I saw that Celery can be used for long time running calculations, but in my case, calculations can be performed on 1 or 3000 rows. I would like to find a solution without using Celery.
Another solution could be to use JavaScript to set a timeout when Firefox is detected as web browser, the to add a error message, I also would like to avoid this.
I expect my app to work well at least on Mozilla Firefox, Safari, Opera and Google Chrome Web browsers.
Thanks for your help !

Having 2 website on the same server using ember-simple-auth logs both out

I currently have 2 of the same site (one for production and the other is a development version) on one server and I have an issue with the ember-simple-auth for both of the site. Whenever I log in on one of the site, it works perfectly fine, the session works and everything works as expected. However, when I have both of the site open on different tabs (on the same browser and same window) and I try logging on one of them, they both log out creating an error in the console saying:
"The authenticator "authenticator:oauth2" rejected to restore the session - invalidating…"
On the other hand, when I have one of the site open on a regular browser and the other one on the same browser but in incognito (no caches), they both work perfectly fine (e.g. none of them logs out and everything works as expectedly). It works perfectly fine too if I open one site in one browser (such as Chrome) and the other site in a different browser (such as Safari).
My first guess is that these 2 different site has the same session used in cache but I could be wrong. If you have any idea on why this occur or you have a solution, please let me know.
Probably both sites are on the same origin and you use the local-storage session-store. Then both will use the ember_simple_auth:session localStorage key.
Probably the easiest thing could be to override the session-store and define a custom key that contains the information if its the dev or production build.
The probably easiest thing is to have both sites on different ports and/or domains so you have a different origin.

Coded UI Test and Firefox 35.0.1 Issue

I'm trying to use microsoft coded ui tests with firefox. This was NOT an issue until Firefox 35.0.1 came out.
Skip to the bottom if you want to know the issue more than the why am I doing it this way:
Why I'm not using Selenium:
With Selenium, when Firefox launches a web driver, it loses it's previous states/cookie settings. I could of course import a cookie. The problem is that if I have multiple users running the test, they'd either have to set up individual lines of code to import their own specific cookie from their own path. This could become a dangerous game if a user decides to use someone elses cookie.
Why I'm using Coded UI Tests:
Certain applications I am running work exclusively with IE and others work exclusively with Firefox. Since I can't record the instances in IE with selenium, I have to should utilize a coded ui test anyway. I could of course also use watin. But at some point, why run Selenium, and watin when I can instead JUST use a coded ui test. Additionally, when going to the url for login with a coded ui test, FF is setup to save my password and cookie. therefore, the user can save their own password/cookie on each machine and just change the input for username which comes via excel spreadsheet. Everyone gets their own test, and no security issues.
The issue:
Since Coded UI tests don't recognize Firefox as a browser, it recognizes Firefox as a windows application. Therefore, edits and buttons in firefox are considered WinEdit and WinButton for firefox while internet explorer uses HtmlEdit and HtmlButton.
When Firefox put out an update, the coded ui test stopped recognizing certain objects in the firefox window. When trying to manually highlight objects/words with the test builder, it puts the blue box at the head of the web page instead of over what I'm clicking selecting. When hardcoding things to select, it doesn't recognize them. Is anyone aware of a workaround for this issue?
Recording on Firefox/Chrome is not supported by Coded UI. You can record your test in IE and Play it across Firefox/Chrome using Selenium components for Coded UI Cross Browser Testing which can be found here https://visualstudiogallery.msdn.microsoft.com/11cfc881-f8c9-4f96-b303-a2780156628d

Why Django blocks simultaneous requests within the same session?

I tried to add sleep(30) at the first line of my view. After that I opened this page in two browser tabs. The first tab loaded the page after 30 seconds, and the second one loaded it in 60 seconds. In the meantime I was able to open pages from another pc just fine. So it looks like Django blocks the concurrent requests from the same client.
This is very well for my app. And I'd like to be sure my site will work this way in the future. However I have not found any documentation or articles describing such Django behaviour. So I'm still not sure if this is a feature or just fortune. Could somebody please explain how and why this works?
What I actually need is to block the session while view is processing. Of course I can use some flags or db transactions. But I'd not like to add a feature that is already implemented in Django.
I use python 2.6.5, django 1.4, ubuntu server, nginx and uwsgi. Tried both postgresql and sqlite.
My uwsgi settings:
<uwsgi>
<pythonpath>/home/admin/app/src</pythonpath>
<app mountpoint="/">
<script>deploy.wsgi</script>
</app>
<workers>4</workers><!-- Not sure this is needed -->
<processes>2</processes>
</uwsgi>
I also got same effect with runserver command.
Actually Django does not block simultaneous requests.
If I run two browsers (for example chrome and firefox) with the same session (by copying the sessionid cookie from the first browser to the second one), blocking does not happen. So, this is a browser feature, and it's not related to Django anyhow. This means I still need to add some blocking feature by myself to make the code safe.