Modify

Opened 4 years ago

Closed 7 months ago

Last modified 7 months ago

#10812 closed defect (fixed)

Error when using code reviews function

Reported by: anonymous Owned by: olemis
Priority: high Component: PeerReviewPlugin
Severity: critical Keywords:
Cc: rjollos, andy.barreras@…, cincth@… Trac Release: 0.12

Description (last modified by rjollos)

Using Trac 1.0 on Apache via PostgresSQL backend. When I click on the "Peer Review" navigation button, I receive the following error:

Trac detected an internal error:

ProgrammingError: relation "codereviews" does not exist
LINE 1: ...iew, Author, Status, DateCreate, Name, Notes FROM CodeReview...
                                                             ^
Python Traceback
Most recent call last:

    File "c:/docume~1/svchou~1/locals~1/temp/easy_install-tyu9e_/Trac-1.0-py2.7-win32.egg.tmp/trac/web/main.py", line 497, in _dispatch_request
    File "c:/docume~1/svchou~1/locals~1/temp/easy_install-tyu9e_/Trac-1.0-py2.7-win32.egg.tmp/trac/web/main.py", line 214, in dispatch
    File "build/bdist.win32/egg/codereview/peerReviewMain.py", line 74, in process_request
    File "build/bdist.win32/egg/codereview/dbBackend.py", line 37, in getMyCodeReviews
    File "build/bdist.win32/egg/codereview/dbBackend.py", line 177, in execCodeReviewQuery
    File "c:/docume~1/svchou~1/locals~1/temp/easy_install-tyu9e_/Trac-1.0-py2.7-win32.egg.tmp/trac/db/util.py", line 66, in execute 

Attachments (0)

Change History (8)

comment:1 Changed 4 years ago by rjollos

  • Description modified (diff)

comment:2 Changed 4 years ago by rjollos

  • Cc andy.barreras@… added

#10822 closed as a duplicate.

comment:3 follow-up: Changed 3 years ago by anonymous

The cheap way to fix this is to change db_default.py to lowercase all the table and column names. The problem stems from the db tables being created with mixed/upper case letters that I assume are quoted during creation but then are not quoted when used (or possibly lower case names are used).

Once I did the change I was able to have the plugin run on both 0.12.2 and 1.0.1 (although it didn't run correctly e.g. no way to add files to a review).

An example of the change is:

#The tables for the Code Review Plugin
tables = [
    Table('codereviews', key='idreview')[
        Column('idreview', auto_increment=True, type='int'),
        Column('author'),
        Column('status'),
        Column('datecreate', type='int'),
        Column('name'),
        Column('notes'),
    ],
...

Note that the table names, key and all column names are lowercase.

Further info on case issues with databases can be found at:

http://www.alberton.info/dbms_identifiers_and_case_sensitivity.html

comment:4 Changed 3 years ago by jun66j5

#11456 was closed as a duplicate.

comment:5 in reply to: ↑ 3 ; follow-up: Changed 3 years ago by rjollos

Replying to anonymous:

The cheap way to fix this is to change db_default.py to lowercase all the table and column names. The problem stems from the db tables being created with mixed/upper case letters that I assume are quoted during creation but then are not quoted when used (or possibly lower case names are used).

As noted in #11456, we'll also need an upgrade step.

There is string interpolation when creating the query strings in dbBackend.py, which should also be fixed.

Generally speaking, this plugin is a mess.

Once I did the change I was able to have the plugin run on both 0.12.2 and 1.0.1 (although it didn't run correctly e.g. no way to add files to a review).

That issue was likely addressed in #11184.

comment:6 in reply to: ↑ 5 ; follow-up: Changed 11 months ago by thenor

Replying to rjollos:

There is string interpolation when creating the query strings in dbBackend.py, which should also be fixed.

Yes, and not only there. E.g. in CodeReviewStruct.py lines 47-51, you find the following code:

cursor.execute("""
    INSERT INTO CodeReviews (Author, Status, DateCreate, Name, Notes)
    VALUES (%s, %s, %s, %s, %s)
           """, (self.Author, self.Status, self.DateCreate,
                 self.Name, self.Notes))
self.IDReview = db.get_last_id(cursor, 'CodeReviews', 'IDReview')

... where the first INSERT succeeds while the get_last_id fails as shown below. Note the superfluous double quotes.

ProgrammingError: relation "CodeReviews_IDReview_seq" does not exist
LINE 1: SELECT CURRVAL('"CodeReviews_IDReview_seq"')

This happens on Trac 1.0.9 on Postgresql/Ubuntu 14.04 even after the fix to db_default.py described above. Fixing is way over my head - which is a pity as the overall idea of the plugin is really good!

comment:7 Changed 7 months ago by Cinc-th

In 15192:

Upgrade for database schema to version 2.

  • all table and column names are lower case now
  • table names are prepended by peer_ to prevent name clashes
  • added some columns for future features
  • uses Trac upgrade framework
  • table contents is properly migrated

Note that the upgrade is only tested with SQLite.

Refs #10812
Refs #5395
Fixes #5808
Fixes #5401



comment:8 in reply to: ↑ 6 Changed 7 months ago by Cinc-th

  • Cc cincth@… added
  • Resolution set to fixed
  • Status changed from new to closed
  • Trac Release changed from 1.0 to 0.12

Replying to thenor:

Replying to rjollos:

There is string interpolation when creating the query strings in dbBackend.py, which should also be fixed.

Yes, and not only there. E.g. in CodeReviewStruct.py lines 47-51, you find the following code:

cursor.execute("""
    INSERT INTO CodeReviews (Author, Status, DateCreate, Name, Notes)
    VALUES (%s, %s, %s, %s, %s)
           """, (self.Author, self.Status, self.DateCreate,
                 self.Name, self.Notes))
self.IDReview = db.get_last_id(cursor, 'CodeReviews', 'IDReview')

... where the first INSERT succeeds while the get_last_id fails as shown below. Note the superfluous double quotes.

ProgrammingError: relation "CodeReviews_IDReview_seq" does not exist
LINE 1: SELECT CURRVAL('"CodeReviews_IDReview_seq"')

This happens on Trac 1.0.9 on Postgresql/Ubuntu 14.04 even after the fix to db_default.py described above. Fixing is way over my head - which is a pity as the overall idea of the plugin is really good!

 db.get_last_id(cursor, 'CodeReviews', 'IDReview')

Should be fixed with [15192] by changing to:

 db.get_last_id(cursor, 'peer_review', 'review_id')

The double quotes are added by the database backend.

If the problem persists open a new ticket.

Last edited 7 months ago by Cinc-th (previous) (diff)

Add Comment

Modify Ticket

Action
as closed The owner will remain olemis.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.