Drupal 4.5 Session.inc Problem

Problemdescription

After a logout the following error message is displayed::

Warning: pg_query(): Query failed: ERROR: null value in
column "uid" violates not-null constraint in
/usr/share/drupal/includes/database.pgsql.inc on line 104

Fatal error: ERROR: null value in column "uid" violates
not-null constraint query: INSERT INTO sessions
(sid, hostname, timestamp) values('706ba15ec1172f8debbf7aba566197f1',
'10.10.10.10', 1125487865) in /usr/share/drupal/includes/database.pgsql.inc
on line 121

Details

The problematic code sequenze in session.inc (function sess_read)::

db_query("INSERT INTO {sessions} (sid, hostname, timestamp)
values('%s', '%s', %d)", $key, $_SERVER["REMOTE_ADDR"], time());

The source code change in the "Drupal CVS":http://cvs.drupal.org/viewcvs/drupal/drupal/includes/session.inc?r1=1.8&... There is no mor uid field!

The Table session::

Table "public.sessions"
Column | Type | Modifiers
-----------+------------------------+----------------------------------------
uid | integer | not null
sid | character varying(32) | not null default ''::character varying
hostname | character varying(128) | not null default ''::character varying
timestamp | integer | not null default 0
session | text |
Indexes:
"sessions_pkey" primary key, btree (sid)

Patch

The following patch fix this problem::

root@local:/usr/share/drupal/includes# diff -u session.inc.ORIG session.inc
--- session.inc.ORIG 2005-08-29 15:14:48.000000000 +0200
+++ session.inc 2005-09-02 19:35:17.794192795 +0200
@@ -26,7 +26,7 @@

if (!db_num_rows($result)) {
$result = db_query("SELECT u.* FROM {users} u WHERE u.uid = 0");
- db_query("INSERT INTO {sessions} (sid, hostname, timestamp) values('%s', '%s', %d)", $key, $_SERVER["REMOTE_ADDR"], time());
+ db_query("INSERT INTO {sessions} (uid, sid, hostname, timestamp) values(0, '%s', '%s', %d)", $key, $_SERVER["REMOTE_ADDR"], time());
}

$user = db_fetch_object($result);

CommentFileSizeAuthor
snapshot3_0.png48.65 KBhstraub

Comments

Cvbge’s picture

Status: Active » Closed (duplicate)

Hello, thank you for your report.
There's similar fix for this in http://drupal.org/node/29143 but it's not yet commited.

Cvbge’s picture

Status: Closed (duplicate) » Fixed

Should be fixed by http://drupal.org/node/29143

Anonymous’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)