kiddouk / redisco

A Python Library for Simple Models and Containers Persisted in Redis
MIT License
438 stars 78 forks source link

Python 3 support #22

Closed tanbro closed 4 years ago

kiddouk commented 11 years ago

Patches are welcome.

stuaxo commented 8 years ago

Initial Patches incoming ....

stuaxo commented 8 years ago

https://github.com/stuaxo/redisco/tree/python3

Here's the start of python3 support. Python3 doesn't work, but all the tests pass for python2.6/2.7 (the other pull requests today were for that).

For 3.x the errors seem to be in two categories:

1) .attributes and .objects being broken 2) python 3 stuff, (getting back bytes instead of unicode).

1)

======================================================================
ERROR: test_indexing (redisco.tests.transplant_class.<locals>.C)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/stu/projects/external/redisco/redisco/models/basetests.py", line 660, in test_indexing
    assert Task.objects.create(name="Study Lua", done=False)
AttributeError: type object 'Task' has no attribute 'objects'

======================================================================
ERROR: test_saved_CharField (redisco.tests.transplant_class.<locals>.C)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/stu/projects/external/redisco/redisco/models/basetests.py", line 648, in test_saved_CharField
    t = Task(name="Cook dinner", done=False)
  File "/home/stu/projects/external/redisco/redisco/models/base.py", line 225, in __init__
    self.update_attributes(**kwargs)
  File "/home/stu/projects/external/redisco/redisco/models/base.py", line 301, in update_attributes
    + self.references.values()
  File "/home/stu/projects/external/redisco/redisco/models/base.py", line 470, in attributes
    return dict(self._attributes)
AttributeError: 'Task' object has no attribute '_attributes'

2)

======================================================================
FAIL: test_common_operations (redisco.tests.transplant_class.<locals>.C)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/stu/projects/external/redisco/redisco/containerstests.py", line 233, in test_common_operations
    self.assertEqual(['a', 'b', 'c', 'd', 'e', 'f'], alpha.all())
AssertionError: Lists differ: ['a', 'b', 'c', 'd', 'e', 'f'] != [b'a', b'b', b'c', b'd', b'e', b'f']

First differing element 0:
a
b'a'

- ['a', 'b', 'c', 'd', 'e', 'f']
+ [b'a', b'b', b'c', b'd', b'e', b'f']
?  +     +     +     +     +     +
stuaxo commented 8 years ago

Current build - https://travis-ci.org/stuaxo/redisco/builds/130556318

Note - a lot of the doctests fail, which is to be expected, but the unicode / bytes thing is probably the biggest thing that needs fixing.

stuaxo commented 8 years ago

Down to one error in the nosetests.

Doctests will probably never pass due to syntax issues.

Notes in detail:

Wrapped filter and map in list() to match py2 behaviour, and make test with
 .append() pass
- we *could* wrap filter in a lazy object to suport .append() instead.

attributes.py:305
models.py:35 and

enable decode_responses on python3.
- matches py2 behaviour, but may not want in long time.

tests/__init__.py:13
redisco/__init__.py:14

Changed one doctest, but naking doctests all py2/3 compatible seems
nigh on impossible.
containers.py
kiddouk commented 8 years ago

@stuaxo Thanks for this great collaborative work on this :)

stuaxo commented 8 years ago

Cheers :)

So, last night I got this working enough that fields (seem) to save and load properly.

Note: decode_responses = True is required.

Today, I'm going to start using it in ${work_project}, so hopefully, things will be working.

I'm not sure what to do about the doctests, but I then having things work as much as they do right now is certainly more useful than no python3 support.

stuaxo commented 8 years ago

BTW - It's probably worth re-opening this bug, for char related to python3 support.

stuaxo commented 8 years ago

@kiddouk - are there some examples of using filters with Redisco?
I can't tell if they don't work in python3, or if I'm just doing stuff wrong.

stuaxo commented 8 years ago

Specifically, I have a model like this:

class Group(models.Model):
    name = models.CharField(indexed=True)

class ScheduledJob(models.Model):
    group = models.ReferenceField(Group, indexed=True, related_name="jobs")

And was expecting to be able to do something like:

ScheduledJob.objects.filter(group__name="blah")

Also - should __in queries work, e.g.

ScheduledJob.objects.filter(name__in=["blah1", "blah2"])

?

stuaxo commented 8 years ago

^ OK, realised that these only work for float like things.

What do you want to do about the python3 branch ?

Doctests can never pass both afaict. So either I can turn those off for py3, or another solution would be to have a separate "redisco3". - Asking, as coming near to end of current project that uses Redisco.

kiddouk commented 8 years ago

I'd say, that I will give it a try next week to see what I can pull here. It would be bad to reduce our test base to support a new version of python.

clovis818 commented 8 years ago

+1

stuaxo commented 4 years ago

Did redisco ever move to python3 ?

I was on a short-term contract using Redisco, once that finished, so did my work on it.