Ticket #34 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

Elixir fails during insert and update on MySQL 5.x when using the list extension.

Reported by: guest Owned by:
Priority: normal Milestone:
Component: extensions Version:
Keywords: acts_as_list, mysql Cc: alice@…

Description

MySQL 5.x requires that sub-selects be given unique aliases to prevent confusion, whereas I assume older versions of MySQL did not enforce this. Attempting to use the elixir.ext.list acts_as_list functionality, I ran into the following Exception: (wrapped with data removed)

sqlalchemy.exceptions.OperationalError: (OperationalError) (1248,
    'Every derived table must have its own alias')
    u'INSERT INTO objects (commission_id, creator_id, location_id, uuid, title, description, filename, mime, created, updated, published, position)
    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, (
        SELECT max(value) AS max_1
            FROM (SELECT max(objects.position) + %s AS value
                FROM objects
                WHERE objects.location_id IS NULL UNION SELECT %s AS value)))'

Attached to this ticket is a patch which solves this problem using an alias of the sub-select.

Attachments

mysql-aliased-subselect-patch.diff (0.7 kB) - added by guest 5 years ago.
Simplest possible patch to solve problem.
elixir_bug_34.patch (444 bytes) - added by guest 5 years ago.
Patch for "You can't specify target table 'objects' for update in FROM clause"

Change History

Changed 5 years ago by guest

Simplest possible patch to solve problem.

Changed 5 years ago by ged

  • status changed from new to closed
  • resolution set to fixed

fixed in r309. Thanks.

Changed 5 years ago by guest

  • status changed from closed to reopened
  • resolution deleted
  • summary changed from Elixir fails during insert on MySQL 5.x when using the list extension. to Elixir fails during insert and update on MySQL 5.x when using the list extension.

I've run into this problem again (OP here) with UPDATE statements related to use of the move_to_bottom method.

I get the following exception: (wrapped for sanity)

OperationalError: (OperationalError)
    (1093, "You can't specify target table 'objects' for update in FROM clause")
    u'''UPDATE objects SET position=(SELECT max(objects.position) + %s AS anon_1
        FROM objects
        WHERE objects.location_id = %s) WHERE objects.id = %s'''
    [1, 1157L, 17890L]

I will submit a patch shortly.

Changed 5 years ago by guest

Patch for "You can't specify target table 'objects' for update in FROM clause"

Changed 4 years ago by ged

  • status changed from reopened to closed
  • resolution set to fixed

I've finally decided to commit the patch anyway (r418).

Note: See TracTickets for help on using tickets.