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

Force a cast from tuple to list on meta['indexes'] & initialize direction variable #531

Closed
wants to merge 2 commits into from

Conversation

agonzalezro
Copy link

I'm using mongoengine with pip and I get this error since I upgrade mongoengine (from a very old version forked by metzlar):

Traceback (most recent call last):
  File "/opt/pypy-1.7/lib-python/2.7/unittest/case.py", line 318, in run
    testMethod()
  File "/var/lib/jenkins/jobs/Xxx/workspace/.env/site-packages/nose-1.1.2-py2.7.egg/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/var/lib/jenkins/jobs/Xxx/workspace/.env/site-packages/nose-1.1.2-py2.7.egg/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/var/lib/jenkins/jobs/Xxx/workspace/.env/site-packages/nose-1.1.2-py2.7.egg/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/var/lib/jenkins/jobs/Xxx/workspace/xxx/auth/__init__.py", line 6, in <module>
    from xxx.auth import views
  File "/var/lib/jenkins/jobs/Xxx/workspace/xxx/auth/views.py", line 16, in <module>
    from xxx.social.client import Client
  File "/var/lib/jenkins/jobs/Xxx/workspace/xxx/social/__init__.py", line 9, in <module>
    from xxx.social import views
  File "/var/lib/jenkins/jobs/Xxx/workspace/xxx/social/views.py", line 11, in <module>
    from xxx.social.models import CheckIn, SocialQuery
  File "/var/lib/jenkins/jobs/Xxx/workspace/xxx/social/models.py", line 7, in <module>
    class CheckIn(db.Document):
  File "/var/lib/jenkins/jobs/Xxx/workspace/.env/site-packages/mongoengine-0.6.13-py2.7.egg/mongoengine/base.py", line 707, in __new__
    indicies = meta['indexes'] + abstract_base_indexes
TypeError: unsupported operand type(s) for +: 'tuple' and 'list'

To fix it I casted meta['indexes'] to list.

I don't know if it's the best way to do it or perhaps a check like:

if type(meta['indexes'] == tuple):
    meta['indexes'] = list(meta['indexes'])

But I don't see the point of this check.

Furthermore, running the tests (of mongoengine) there is a variable called direction that is not initialized. I initialized it to None, but I get 4 more failures.

@rozza
Copy link

rozza commented Jul 2, 2012

Can you post your model definition?

Indexes is expected to be a list not a tuple - but I can update. I'm more interested on how your tripping over direction in the index spec method.

@agonzalezro
Copy link
Author

Hi Rozza,

First of all thank you very much for you quick reply.

This is the model, with some anonymized name, but with all the fields:

class CheckIn(db.Document):
    user = db.ReferenceField(User, required=True, reverse_delete_rule=db.CASCADE)
    foo_bar = db.IntField(required=True)
    subject = db.StringField(max_length=128,
                             default='*',
                             unique_with=('user', 'foo_bar'))
    meta = {'indexes': ('user', 'foo_bar', 'subject')}
    datetime = db.DateTimeField(required=True)

If you need anything else, please, let me know!

rozza added a commit to MongoEngine/mongoengine that referenced this pull request Jul 11, 2012
@rozza rozza closed this Jul 11, 2012
@rozza
Copy link

rozza commented Jul 11, 2012

Fixed - thanks for the patch.

@agonzalezro
Copy link
Author

Thanks for patch it!

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

Successfully merging this pull request may close these issues.

None yet

2 participants