Closed tanbro closed 4 years ago
Initial Patches incoming ....
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']
? + + + + + +
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.
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
@stuaxo Thanks for this great collaborative work on this :)
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.
BTW - It's probably worth re-opening this bug, for char related to python3 support.
@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.
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"])
?
^ 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.
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.
+1
Did redisco
ever move to python3 ?
I was on a short-term contract using Redisco, once that finished, so did my work on it.
Patches are welcome.