Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when inserting multiple rows #251

Open
samuelcolvin opened this issue Jan 13, 2017 · 4 comments
Open

error when inserting multiple rows #251

samuelcolvin opened this issue Jan 13, 2017 · 4 comments

Comments

@samuelcolvin
Copy link
Member

This was the error I was getting when I posted #250, however that issue is about something else so I thought preferable to create a new issue.

I'm getting the exception below sometimes when running insert with multiple values.

What's odd is I don't seem to always get it but I can't work out what's correlating with the exception happening. I never get it with single value inserts.

    cur = await conn.execute(sa_subjects.insert().values(values))
  File "/home/samuel/code/socket-server/env/lib/python3.6/site-packages/aiopg/utils.py", line 72, in __await__
    resp = yield from self._coro
  File "/home/samuel/code/socket-server/env/lib/python3.6/site-packages/aiopg/sa/connection.py", line 88, in _execute
    compiled_parameters = [compiled.construct_params(dp)]
  File "/home/samuel/code/socket-server/env/lib/python3.6/site-packages/aiopg/sa/engine.py", line 25, in construct_params
    pd[column.key] = self._exec_default(column.default)
  File "/home/samuel/code/socket-server/env/lib/python3.6/site-packages/aiopg/sa/engine.py", line 35, in _exec_default
    return default.arg
AttributeError: 'Sequence' object has no attribute 'arg'

If I print default I get:

Sequence('subject_id_seq', metadata=MetaData(bind=None))

This appears to be the sequence object I created on the primary key field of the table.

Sequence doesn't have an arg field, it looks like _exec_default is expecting a ColumnDefault not Sequence, I can't work out why it's receiving a Sequence not ColumnDefault sometimes.

The table is very simple, just

class Subject(Base):
    __tablename__ = 'subjects'

    id = Column(Integer, Sequence('subject_id_seq'), primary_key=True, nullable=False)
    name = Column(String(63), nullable=False, index=True)
    category = Column(String(63), nullable=False, index=True)

    __table_args__ = (
        UniqueConstraint('name', 'category', name='_subject_name_cat'),
    )

sa_subjects = Subject.__table__
@samuelcolvin
Copy link
Member Author

I think the intermittency was because either: the table didn't have a sequence on the primary key (different table from above) or there was only one value in values the standard "create a single item" logic was employed.

Otherwise I seem to get this error all the time.

@samuelcolvin samuelcolvin changed the title intermittent error when inserting multiple rows error when inserting multiple rows Jan 13, 2017
@jettify
Copy link
Member

jettify commented Jan 13, 2017

@vir-mir could you please take a look on this issue?

@samuelcolvin
Copy link
Member Author

samuelcolvin commented Jan 13, 2017

Ok, this issue is related to the explicit use of Sequence('subject_id_seq') removing that (and thereby using the default SERIAL as per this) seems to solve the problem.

Still an error through, currently as far as I can tell Sequence breaks insert() with multiple values.

@vir-mir
Copy link
Member

vir-mir commented Jan 14, 2017

@samuelcolvin @jettify Hi. I'm look to next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants