The following ActiveRecord calls result in InvalidStatement errors. This occurs when I even provide a hard-coded userid. The session dump shows a session variable "user_id" that has a valid value as well. Can someone help?
def index
#nav = []
#user = B2bUser.find(request.session[:user_id])
#privileges = B2bPrivilege.lookup_all request.session[:user_id]
end
## lookup_all method from b2b_privilege model
def B2bPrivilege.lookup_all current_user_id
return B2bPrivilege.find_by_sql("SELECT b2b_privileges.*, vendors.name AS vendor_name FROM b2b_privileges LEFT JOIN vendors ON vendors.id = b2b_privileges.vendor_id WHERE b2b_user_id = ?", current_user_id)
end
Processing by HomeController#index as HTML
Could not log "sql.active_record" event. NoMethodError: undefined method `name' for nil:NilClass
PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ..."b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LI...
^
: SELECT "b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LIMIT 1
Completed 500 Internal Server Error in 13ms
ActiveRecord::StatementInvalid (PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ..."b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LI...
^
: SELECT "b2b_users".* FROM "b2b_users" WHERE "b2b_users"."" = $1 LIMIT 1):
app/controllers/home_controller.rb:7:in `index'
Related
I've tried below to send a param to separate feature file ( by following this example ) but, it is not working as expected.
project.feature
* def id = '55000000005021'
* def result = call read('delete_project.feature')
delete_project.feature
Given path 'project', '#(id)'
When method DELETE
Then status 200
Then match response.status == 'success'
Getting below exception
com.intuit.karate.exception.KarateException: projects.feature:48 -
delete_project.feature:11 - status code was: 404, expected: 200,
response time: 239, url: https://localhost:8080/project/%23(id)
response:
{"status":"failure","data":{"error_code":"INVALID_URL_PATTERN","message":"Please
check if the URL trying to access is a correct one"}} at ✽.* def
result = call read('delete_project.feature') (projects.feature:48)
One more doubt, How to iterate this by passing list of ids. I've multiple id in foo variable, I would like call delete_project.feature for each id availble in that foo variable.
* def foo = get response.data[*].id
I think you over-complicated the path params, change to:
Given path 'project', id
And read this part of the docs: https://github.com/intuit/karate#rules-for-embedded-expressions
So... I dont know what to say, im going to be quick obviously
CODE:
#bot.event
async def on_server_role_update(role, before, after):
print("[" + (colored("{}".format(role.server), 'blue')) + "] " + (colored("Role Updated: {0} >> {1}".format(before, after), 'yellow')))
ERROR:
TypeError: on_server_role_update() missing 1 positional argument: 'after'
You see? I have the argument but it shows an error!
on_server_role_update should have exactly two arguments: a Role before and a Role after. Why did you think there was a third role argument?
#bot.event
async def on_server_role_update(before, after):
server_blue = colored(str(before.server), 'blue')
msg = "Role Updated: {0} >> {1}".format(before, after)
color_msg = colored(msg, 'yellow')
print("[{}] {}".format(server_blue, color_msg))
<?php
include('connect.php');
$date = $_POST['date'];
$student_ID = $_POST['student_ID'];
$full_name = $_POST['full_name'];
$year_section = $_POST['year_section'];
$payment_description = $_POST['payment_description'];
$amount = $_POST['amount'];
$received_by = $_POST['received_by'];
// query
$sql = "INSERT INTO transaction (date,student_ID,full_name,year_section,payment_description,amount,received_by) VALUES (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd,:ft)";
$q = $db->prepare($sql);
$q>execute(array(':sas'=>$date,':asas'=>$student_ID,':asafs'=>$full_name,':offff'=>$year_section,':statttt'=>$payment_description,':dot'=>$amount,':rd'=>$received_by));
header("location: index.php");
?>
I get the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables
does not match number of tokens' in
C:\xampp\htdocs\recordmanagement\main\reg.php:15 Stack trace: #0
C:\xampp\htdocs\recordmanagement\main\reg.php(15):
PDOStatement->execute(Array) #1 {main} thrown in
C:\xampp\htdocs\recordmanagement\main\reg.php on line 15
In the code I am also unsure about the meaning of these values:
(:sas,:asas,:asafs,:offff,:statttt,:dot,:rd,:ft);
I downloaded it from sourcecode, so it was not written by me.
There seems to be a field to much in the query. This:
$sql = "INSERT INTO transaction
(date,student_ID,full_name,year_section,payment_description,amount,received_by)
VALUES (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd,:ft)";
should probably be:
$sql = "INSERT INTO transaction
(date,student_ID,full_name,year_section,payment_description,amount,received_by)
VALUES (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd)";
as there is no matching value for the :ft field.
Whether this is because your missing an item in the values or if it's not needed I can't say.
Updated question:
Django is giving me the following sql query:
SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" = %s args=('andrew',);
If I execute the sql query in the postgresql command line, I get the following error:
ERROR: syntax error at or near "%"
LINE 1: ..." FROM "auth_user" WHERE "auth_user"."username" = %s args=(...
^
However, when I slightly modify the statement, then I get the cirrect result from postgresql.
SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" = 'andrew';
Is the Django generated query incorrect?
Hi Stackoverflow people,
Very simple code which drives me crazy:
I want to extract the user information from user_auth with
user = get_object_or_404(User, pk = request.user.pk)
However, I get an error message in Django:
'NoneType' object does not support item assignment
When I check the sql query and execute it in the psql command line, psql gives me also an error message, which makes me thinking that the statement might be incorrect.
psql statement is:
SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = %s ; args=(7,)
Why does it say %s in the WHERE statement? The user id is not a string.
I believe the solution must be very simple - but I can figure out what the issue is here.
Thank you for your help and suggestions!
Additional explanation
I am using the django_social_auth package for the user authentification. The user will be directed to the dashboard site once the 3rd part cleared the credentials, therefore I would assume that request.user is not None.
Complete traceback
Environment:
Request Method: GET
Request URL: http://login.test.com:8000/profile/dashboard/
Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.gis',
'django.contrib.messages',
'django.contrib.markup',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.humanize',
'guardian',
'easy_thumbnails',
'userena',
'userena.contrib.umessages',
'south',
'django_extensions',
'debug_toolbar',
'social_auth',
'djangoratings',
'about',
'apps.profiles',
'apps.map',
'apps.contact',
]
Installed Middleware:
['django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Traceback:
File "/Users/neurix/Development/test/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/neurix/Development/test/test/apps/profiles/views.py" in dashboard
35. extra_context['username'] = user.username
Exception Type: TypeError at /profile/dashboard/
Exception Value: 'NoneType' object does not support item assignment
views.py
...
31: print "user: %s" %(request.user.pk)
32: user = get_object_or_404(User, pk = request.user.pk)
33:
34:
35: extra_context['username'] = user.username
36: if user.first_name:
37: extra_context['name'] = user.first_name
...
Could it be that request.user is None?
if request.user is not None:
user = get_object_or_404(User, pk = request.user.pk)
I'm getting the following error:
NoMethodError in Users#new
Showing .../app/views/users/form/_new.haml where line #7 raised:
undefined method `on' for #<ActiveModel::Errors:0x007fb599ec6610>
The code in line 7 is:
7: = errors_for user, :first_name
And the application_helper.rb:
def errors_for(model, field)
error = case errors = model.errors.on(field)
...
end
'on' is a default method in ActiveRecord. Why doesn't this work?
If you're using Rails 3, then the problem is that there's no "on" method for the Errors class anymore. I think you're supposed to use "get" now. So:
error = case errors = model.errors.get(field)
Or...
error = case errors = model.errors[field]
I checked my user and u.errors is an ActiveRecord::Errors, while I see you have an ActiveModel::Error, I would work on that.
Then I don't understand case errors = statement in your helper, I'm curious to know how you implemented that part...