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

StatementError: (exceptions.AttributeError) 'str' object has no attribute 'value' when iterating Updates #1023

Closed
bowlofeggs opened this issue Oct 12, 2016 · 1 comment
Assignees
Labels
Crash Issues related to an unhandled crash Critical We can't go on living in this sqalor, drop everything and fix it!

Comments

@bowlofeggs
Copy link
Contributor

In testing #1011 I found an Exception when iterating Update objects that I've been able to reproduce outside of that pull request:

[vagrant@localhost tools]$ pshell /vagrant/development.ini 
2016-10-12 13:45:07,923 WARNI [fedmsg.crypto.x509][MainThread] Crypto disabled ImportError('No module named M2Crypto',)
2016-10-12 13:45:07,923 WARNI [fedmsg.crypto.x509][MainThread] Crypto disabled ImportError('No module named M2Crypto',)
2016-10-12 13:45:07,968 INFO  [bodhi][MainThread] Using the FakeBugTracker
2016-10-12 13:45:08,025 DEBUG [bodhi][MainThread] Using DevBuildsys
Python 2.7.12 (default, Sep 29 2016, 13:30:34) 
[GCC 6.2.1 20160916 (Red Hat 6.2.1-2)] on linux2
Type "help" for more information.

Environment:
  app          The WSGI application.
  registry     Active Pyramid registry.
  request      Active request object.
  root         Root of the default resource tree.
  root_factory Default root factory used to create `root`.

Custom Variables:
  m            bodhi.server.models
  t            transaction

>>> execfile('tools/shelldb.py')
>>> q = db.query(m.Update).filter(m.Update.request.in_(['testing']))
>>> for update in q.all():
...     print update.alias
... 
2016-10-12 13:49:16,483 INFO  [sqlalchemy.engine.base.Engine][MainThread] select version()
2016-10-12 13:49:16,484 INFO  [sqlalchemy.engine.base.Engine][MainThread] {}
2016-10-12 13:49:16,485 INFO  [sqlalchemy.engine.base.Engine][MainThread] select current_schema()
2016-10-12 13:49:16,485 INFO  [sqlalchemy.engine.base.Engine][MainThread] {}
2016-10-12 13:49:16,486 INFO  [sqlalchemy.engine.base.Engine][MainThread] SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2016-10-12 13:49:16,487 INFO  [sqlalchemy.engine.base.Engine][MainThread] {}
2016-10-12 13:49:16,487 INFO  [sqlalchemy.engine.base.Engine][MainThread] SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2016-10-12 13:49:16,487 INFO  [sqlalchemy.engine.base.Engine][MainThread] {}
2016-10-12 13:49:16,488 INFO  [sqlalchemy.engine.base.Engine][MainThread] show standard_conforming_strings
2016-10-12 13:49:16,489 INFO  [sqlalchemy.engine.base.Engine][MainThread] {}
2016-10-12 13:49:16,489 INFO  [sqlalchemy.engine.base.Engine][MainThread] BEGIN (implicit)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2613, in all
    return list(self)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2761, in __iter__
    return self._execute_and_instances(context)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2776, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1078, in _execute_context
    None, None)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1073, in _execute_context
    context = constructor(dialect, self, conn, *args)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 600, in _init_compiled
    for key in compiled_params
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 600, in <genexpr>
    for key in compiled_params
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/type_api.py", line 982, in process
    return process_param(value, dialect)
  File "/vagrant/bodhi/server/models/enum.py", line 109, in process_bind_param
    return value.value
StatementError: (exceptions.AttributeError) 'str' object has no attribute 'value' [SQL: u'SELECT updates.id AS updates_id, updates.title AS updates_title, updates.karma AS updates_karma, updates.autokarma AS updates_autokarma, updates.stable_karma AS updates_stable_karma, updates.unstable_karma AS updates_unstable_karma, updates.requirements AS updates_requirements, updates.require_bugs AS updates_require_bugs, updates.require_testcases AS updates_require_testcases, updates.notes AS updates_notes, updates.type AS updates_type, updates.status AS updates_status, updates.request AS updates_request, updates.severity AS updates_severity, updates.suggest AS updates_suggest, updates.locked AS updates_locked, updates.pushed AS updates_pushed, updates.critpath AS updates_critpath, updates.close_bugs AS updates_close_bugs, updates.date_submitted AS updates_date_submitted, updates.date_modified AS updates_date_modified, updates.date_approved AS updates_date_approved, updates.date_pushed AS updates_date_pushed, updates.date_testing AS updates_date_testing, updates.date_stable AS updates_date_stable, updates.date_locked AS updates_date_locked, updates.alias AS updates_alias, updates.old_updateid AS updates_old_updateid, updates.release_id AS updates_release_id, updates.user_id AS updates_user_id, releases_1.id AS releases_1_id, releases_1.name AS releases_1_name, releases_1.long_name AS releases_1_long_name, releases_1.version AS releases_1_version, releases_1.id_prefix AS releases_1_id_prefix, releases_1.branch AS releases_1_branch, releases_1.dist_tag AS releases_1_dist_tag, releases_1.stable_tag AS releases_1_stable_tag, releases_1.testing_tag AS releases_1_testing_tag, releases_1.candidate_tag AS releases_1_candidate_tag, releases_1.pending_signing_tag AS releases_1_pending_signing_tag, releases_1.pending_testing_tag AS releases_1_pending_testing_tag, releases_1.pending_stable_tag AS releases_1_pending_stable_tag, releases_1.override_tag AS releases_1_override_tag, releases_1.state AS releases_1_state, comments_1.id AS comments_1_id, comments_1.karma AS comments_1_karma, comments_1.karma_critpath AS comments_1_karma_critpath, comments_1.text AS comments_1_text, comments_1.anonymous AS comments_1_anonymous, comments_1.timestamp AS comments_1_timestamp, comments_1.update_id AS comments_1_update_id, comments_1.user_id AS comments_1_user_id, releases_2.id AS releases_2_id, releases_2.name AS releases_2_name, releases_2.long_name AS releases_2_long_name, releases_2.version AS releases_2_version, releases_2.id_prefix AS releases_2_id_prefix, releases_2.branch AS releases_2_branch, releases_2.dist_tag AS releases_2_dist_tag, releases_2.stable_tag AS releases_2_stable_tag, releases_2.testing_tag AS releases_2_testing_tag, releases_2.candidate_tag AS releases_2_candidate_tag, releases_2.pending_signing_tag AS releases_2_pending_signing_tag, releases_2.pending_testing_tag AS releases_2_pending_testing_tag, releases_2.pending_stable_tag AS releases_2_pending_stable_tag, releases_2.override_tag AS releases_2_override_tag, releases_2.state AS releases_2_state, builds_1.id AS builds_1_id, builds_1.nvr AS builds_1_nvr, builds_1.epoch AS builds_1_epoch, builds_1.inherited AS builds_1_inherited, builds_1.package_id AS builds_1_package_id, builds_1.release_id AS builds_1_release_id, builds_1.update_id AS builds_1_update_id, users_1.id AS users_1_id, users_1.name AS users_1_name, users_1.email AS users_1_email, users_1.show_popups AS users_1_show_popups, buildroot_overrides_1.id AS buildroot_overrides_1_id, buildroot_overrides_1.build_id AS buildroot_overrides_1_build_id, buildroot_overrides_1.submitter_id AS buildroot_overrides_1_submitter_id, buildroot_overrides_1.notes AS buildroot_overrides_1_notes, buildroot_overrides_1.submission_date AS buildroot_overrides_1_submission_date, buildroot_overrides_1.expiration_date AS buildroot_overrides_1_expiration_date, buildroot_overrides_1.expired_date AS buildroot_overrides_1_expired_date, packages_1.id AS packages_1_id, packages_1.name AS packages_1_name, packages_1.requirements AS packages_1_requirements, packages_1.stack_id AS packages_1_stack_id \nFROM updates LEFT OUTER JOIN releases AS releases_1 ON releases_1.id = updates.release_id LEFT OUTER JOIN comments AS comments_1 ON updates.id = comments_1.update_id LEFT OUTER JOIN builds AS builds_1 ON updates.id = builds_1.update_id LEFT OUTER JOIN releases AS releases_2 ON releases_2.id = builds_1.release_id LEFT OUTER JOIN buildroot_overrides AS buildroot_overrides_1 ON builds_1.id = buildroot_overrides_1.build_id LEFT OUTER JOIN users AS users_1 ON users_1.id = buildroot_overrides_1.submitter_id LEFT OUTER JOIN packages AS packages_1 ON packages_1.id = builds_1.package_id \nWHERE updates.request IN (%(request_1)s) ORDER BY comments_1.timestamp'] [parameters: [immutabledict({})]]
@bowlofeggs bowlofeggs added Critical We can't go on living in this sqalor, drop everything and fix it! Crash Issues related to an unhandled crash labels Oct 12, 2016
@bowlofeggs bowlofeggs self-assigned this Oct 12, 2016
@bowlofeggs
Copy link
Contributor Author

I spent some time investigating this and it turns out that you have to query with a DeclEnum parameter, and cannot search with a string (even though searching with a string seems pretty natural).

While looking into this, I filed #1024 to clarify some types in the function that was raising the Exception. I had also written a test, but I decided that the test was a little pointless so I didn't include it in a pull request:

rbarlow@planck ~/d/bodhi> git diff
diff --git a/bodhi/tests/server/models/test_models.py b/bodhi/tests/server/models/test_models.py
index 46d47c8..ca5e4f3 100644
--- a/bodhi/tests/server/models/test_models.py
+++ b/bodhi/tests/server/models/test_models.py
@@ -613,6 +613,19 @@ class TestUpdate(ModelTest):
         for value in mail.MESSAGES.values():
             value['body'] % value['fields']('guest', self.obj)

+    def test_filter_on_request(self):
+        """
+        There was an issue with iterating on a query that filtered by request. This test ensures that such
+        queries function correctly.
+
+        https://github.com/fedora-infra/bodhi/issues/1023
+        """
+        query = self.db.query(model.Update).filter(model.Update.request.in_([model.UpdateRequest.testing]))
+
+        update_aliases = [u.title for u in query.all()]
+
+        assert update_aliases == ['TurboGears-1.0.8-3.fc11']
+
     @mock.patch('bodhi.server.mail.get_template')
     def test_send_update_notice_message_template_fedora(self, get_template):
         """Ensure update message template reflects fedora when it should"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash Issues related to an unhandled crash Critical We can't go on living in this sqalor, drop everything and fix it!
Projects
None yet
Development

No branches or pull requests

1 participant