Issues converting database from sqlite to postgres - postgresql

Recently deployed a new webapp to Heroku. The app was prototyped using SQLite and am having difficulty with the database implementation in Heroku which uses postgresql. Namely, I am receiving this error and I am not sure how to troubleshoot:
2020-05-10T13:22:15.250905+00:00 app[web.1]: HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
2020-05-10T13:22:15.250906+00:00 app[web.1]:
2020-05-10T13:22:15.250906+00:00 app[web.1]: [SQL: SELECT count(*) AS count_1
2020-05-10T13:22:15.250907+00:00 app[web.1]: FROM (SELECT favorites.fav_id AS favorites_fav_id, favorites.user_id AS favorites_user_id, favorites.post_id AS favorites_post_id, favorites.fav_date AS favorites_fav_date
2020-05-10T13:22:15.250907+00:00 app[web.1]: FROM favorites
2020-05-10T13:22:15.250907+00:00 app[web.1]: WHERE favorites.post_id = %(post_id_1)s) AS anon_1]
2020-05-10T13:22:15.250908+00:00 app[web.1]: [parameters: {'post_id_1': 1}]
2020-05-10T13:22:15.250908+00:00 app[web.1]: (Background on this error at: http://sqlalche.me/e/f405)
2020-05-10T13:22:15.255615+00:00 app[web.1]: 10.31.64.150 - - [10/May/2020:13:22:15 +0000] "GET /home HTTP/1.1" 500 290 "https://benchofthoughts.herokuapp.com/post/new" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36"
2020-05-10T13:22:15.254572+00:00 heroku[router]: at=info method=GET path="/home" host=benchofthoughts.herokuapp.com request_id=1eed4376-3745-471d-8623-70217574197a fwd="47.20.85.233" dyno=web.1 connect=1ms service=31ms status=500 bytes=767 protocol=https
From reading this question and this question it looks like the query is trying to use a string instead of an int as the key to pull the relevant data, but this seemed to work fine using the prototype database. I am using SQLAlchemy for the queries so I assume the right variable types are implicitly being used, but I am not sure.
Can someone point me in the right direction to address this error?

Related

Vercel gives error 504 for all API requests on cold boots, but works on warm boots

Every time I open my web app after a while, the first request always returns 504 Gateway Timeout error. However, the immediate subsequent request return data with status 200. This is true for almost every API route. The error log on vercel looks like:
GET] /api/villages?subdistrict=4231
12:14:52:06
Function Status: None
Edge Status: 504
Duration: 10010.66 ms
Init Duration: N/A
Memory Used: 118 MB
ID: rq8d4-1628059491869-fecd750a64de
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.62
2021-08-04T06:45:02.214Z 10867116-4d89-4559-b976-14418b6f5102 Task timed out after 10.01 seconds
I first suspected that the error is with MongoDB connection, however it works just fine if I build the project on my local machine. The waiting period is always below 500ms.
I don't know how to solve or even diagnose this issue as the site is already in production, and the error occurs only when deployed on Vercel. Please help me solve the issue.

Signup/login page working in localhost, but on Heroku I get an Application error (h12/ 503)

I'm able to signup as a user and login as a user successfully on my local host, but on Heroku I receive an application error. It looks like the request is a timeout issue (H12 / 503 error). I'm confused because the login and signup was working fine about a month ago. I took a break from the project and at the time Heroku was deployed successfully and was working. Now I'm having problems on Heroku and don't know how I can fix the issue or what caused it in the first place.
This is my heroku log -
2021-04-13T03:30:27.742004+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/auth/signup" host=reciperec-cristina.herokuapp.com request_id=e0e634e0-fd8e-4517-b428-f319e6beaddb fwd="73.202.97.117" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https

Running sonarqube in Docker keeps redirecting me back to login page

I've had SonarQube running for a good while but haven't used it very much but in general stuff seems to have been working. I'm running it inside Docker.
I just updated it to LTS (6.7) and after that it seems to have gone into some limbo state. I'm able to log in and browse the website but as soon as I try to perform some operation (seems to not matter what that operation is), I get redirected to the login page. If I log in again, everything repeats. So I'm unable to actually perform any action it seems.
At first I thought this had to have something to do with old data conflicting with the new setup. So I cleaned everything out and set it up from scratch. The problem remains, I'm unable to do anything and get redirected to the login page every time.
For example, after the clean setup, I log in with admin/admin and I get the "first time tutorial" where I'm offered to create a token. I tried to do that but get directed to the login page. I log in again and this time I try to skip the tutorial but then I get redirected to the login page. Below is a part of the access.log for when I try to skip the tutorial:
10.3.1.119 - - [16/Nov/2017:00:12:48 +0000] "POST /gor-sq/api/users/skip_onboarding_tutorial HTTP/1.0" 401 - "https://build.acme.com/gor-sq/projects" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "AV/CJhNZndR3RsZuAAA4"
10.3.1.119 - - [16/Nov/2017:00:12:48 +0000] "GET /gor-sq/api/users/identity_providers HTTP/1.0" 200 24 "https://build.acme.com/gor-sq/sessions/new?return_to=%2Fgor-sq%2Fprojects" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "AV/CJhNZndR3RsZuAAA5"
10.3.1.119 - - [16/Nov/2017:00:12:48 +0000] "GET /gor-sq/api/navigation/global HTTP/1.0" 200 573 "https://build.acme.com/gor-sq/sessions/new?return_to=%2Fgor-sq%2Fprojects" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "AV/CJhNZndR3RsZuAAA6"
The first line indicates that the POST is getting a 401 response. Without being absolutely certain, it does look like it's the POST operations that are getting 401 responses while GET works.
This setup does sit behind a reverse proxy but as I said before, the setup has been working fine before and no changes have been made to the reverse proxy setup.
Hope I am not so late. I had the same issue. What worked for me is the deleting cookies from the browser and everything else works like a charm.
I had the same issue.
https://myserver.com/sonar/api/users/skip_onboarding_tutorial
I got 401 and I was redirected to the Login page. I looked at the source code and request.ts was erroring out at line 108.
submit(): Promise<Response> {
const { url, options } = this.getSubmitData({ ...getCSRFToken() });
return window.fetch((window as any).baseUrl + url, options);}
Looked like an issue with the CSRFToken. Since I have Sonarqube running behind a Nginx Reverse Proxy, there might have been something to do with the way I was handling the cookies.
So when I looked a little bit, I found the solution here:
https://stackoverflow.com/a/47909810/3221249
Basically, they changed the way you handle secure cookies after v6.0. Since I was making the cookie secure and httponly to true(not letting the client browser interact with the js code) I was having the above issue. I was doing this even before my non-ssl traffic hits Nginx. I have another proxy server running HAProxy which was handling this so I commented that part of the definitions.
#rspirep ^(Set-cookie:.*) \1;\ Secure if ! secure
#rspirep ^(Set-cookie:.*) \1;\ httponly
I hope this helps you.

Connect only when necessary

I have a big application, where I use cache.
I have alot of pages where my application only connect and disconnect to the database.
Is it possible? connect only when my model really need to fetch data from the database?
I made my connection into a bootstrap. If I remove it, my model can made connection automatic?
-- edited
I made the modify into Zend_Db_Adapter_Pdo_Abstract::_connect()
$debug = getenv("APPLICATION_DEBUG");
if($debug == 1) {
$log = "[" . date("H:i:s") . "] Initializing database connection";
Zend_Registry::get("debug")->Log($log);
}
And
//
if($debug == 1) {
$log = "[" . date("H:i:s") . "] Database connection initialized";
Zend_Registry::get("debug")->Log($log);
}
My debug method save an file into application/tmp/logs/debug. This method show all executed queries and time. When my page are in cache, any query are executed
Date: Sep 10 2013 10:38:12
Access From: ::1
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Filename: /media/backup/www/primeseven.com.br/library/Prime/Debug.php
Access URL: http://localhost/primeseven.com.br/
Referer: http://localhost/
Request method: GET
POST params:
===========================================
[10:38:12] Application initialized
[10:38:12] Initializing database connection
[10:38:12] Database connection initialized
===========================================
Total time: 1.339390039444
Queries: 0
Why you made db connection into bootstrap? Just try to use models and Zend_Db_Table_Abstract http://framework.zend.com/manual/1.12/en/learning.quickstart.create-model.html
The connection will be opened only by using the model.

Facebook Sinatra app doing strange redirects

We have a Facebook application implemented as tabs in a page. However, for certain users, it does weird redirects. This doesn't happen for everyone though, which is why I can't wrap my head around it.
When I go in Chrome incognito mode to our page without being logged in, it seems to happen to me too. What happens exactly?
The multiple tabs on the left of the page are our application tabs. However, something seems to go wrong when clicking on them. I always get the same frontpage, which is the 'Socialabs' page. My heroku logs indicate this:
2012-02-17T14:29:09+00:00 app[web.1]: 193.191.150.2 - - [17/Feb/2012 14:29:09] "POST /small HTTP/1.1" 302 - 0.0025
2012-02-17T14:29:09+00:00 heroku[router]: POST socialapp.herokuapp.com/small dyno=web.1 queue=0 wait=0ms service=28ms status=302 bytes=0
2012-02-17T14:29:09+00:00 app[web.1]: 193.191.150.2 - - [17/Feb/2012 14:29:09] "GET / HTTP/1.1" 302 - 0.0009
2012-02-17T14:29:09+00:00 heroku[router]: GET socialapp.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=10ms status=302 bytes=0
2012-02-17T14:29:09+00:00 app[web.1]: 193.191.150.2 - - [17/Feb/2012 14:29:09] "GET /tab HTTP/1.1" 200 2173 0.0112
2012-02-17T14:29:09+00:00 heroku[router]: GET socialapp.herokuapp.com/tab dyno=web.1 queue=0 wait=0ms service=14ms status=200 bytes=2173
What seems to happen when a user visits, in this case, the 'Small' tab is as follows:
a POST happens to the /small route of our application. This is to be expected. However, instead of rendering our erb template for that route, we get another redirect: /. This route redirects to /tab, as specified in our routes.
I can't figure out why /small redirects to /. The route looks like this in our sinatra application:
get "/contact" do
erb :contact
end
post "/contact" do
#on fb post we redirect to get route and display view
redirect '/contact'
end
I really can't figure this out. The complete contents of my app.rb file can be found in this gist: https://gist.github.com/1864561
Thanks in advance
From your app.rb you have:
before do
# HTTPS redirect
if settings.environment == :production && request.scheme != 'https'
redirect "https://#{request.env['HTTP_HOST']}"
end
end
I don't know the Facebook api or how their apps work, but it looks like it could be this filter that's redirecting any none https request to /.