Re: Index failure after upgrade to ReviewBoard 2.5.16

2017-10-10 Thread 'Rob Backhurst' via reviewboard
Here you go...

# encoding: utf-8
from __future__ import unicode_literals

import re

from django.template import Context, loader
from django.utils import datetime_safe, six

from haystack.exceptions import SearchFieldError
from haystack.utils import get_model_ct_tuple


class NOT_PROVIDED:
pass


DATETIME_REGEX = 
re.compile('^(?P\d{4})-(?P\d{2})-(?P\d{2})(T|\s+)(?P\d{2}):(?P\d{2}):(?P\d{2}).*?$')


# All the SearchFields variants.

class SearchField(object):
"""The base implementation of a search field."""
field_type = None

def __init__(self, model_attr=None, use_template=False, 
template_name=None,
 document=False, indexed=True, stored=True, faceted=False,
 default=NOT_PROVIDED, null=False, index_fieldname=None,
 facet_class=None, boost=1.0, weight=None):
# Track what the index thinks this field is called.
self.instance_name = None
self.model_attr = model_attr
self.use_template = use_template
self.template_name = template_name
self.document = document
self.indexed = indexed
self.stored = stored
self.faceted = faceted
self._default = default
self.null = null
self.index_fieldname = index_fieldname
self.boost = weight or boost
self.is_multivalued = False

# We supply the facet_class for making it easy to create a faceted
# field based off of this field.
self.facet_class = facet_class

if self.facet_class is None:
self.facet_class = FacetCharField

self.set_instance_name(None)

def set_instance_name(self, instance_name):
self.instance_name = instance_name

if self.index_fieldname is None:
self.index_fieldname = self.instance_name

def has_default(self):
"""Returns a boolean of whether this field has a default value."""
return self._default is not NOT_PROVIDED

@property
def default(self):
"""Returns the default value for the field."""
if callable(self._default):
return self._default()

return self._default

def prepare(self, obj):
"""
Takes data from the provided object and prepares it for storage in 
the
index.
"""
# Give priority to a template.
if self.use_template:
return self.prepare_template(obj)
elif self.model_attr is not None:
# Check for `__` in the field for looking through the relation.
attrs = self.model_attr.split('__')
current_object = obj

for attr in attrs:
if not hasattr(current_object, attr):
raise SearchFieldError("The model '%s' ('%s' -- %s) does not have a 
model_attr '%s' (%s)." % (repr(obj), repr(current_object), 
current_object.__class__.__name__, attr, hasattr(current_object, attr)))

current_object = getattr(current_object, attr, None)

if current_object is None:
if self.has_default():
current_object = self._default
# Fall out of the loop, given any further attempts 
at
# accesses will fail misreably.
break
elif self.null:
current_object = None
# Fall out of the loop, given any further attempts 
at
# accesses will fail misreably.
break
else:
raise SearchFieldError("The model '%s' has an empty 
model_attr '%s' and doesn't allow a default or null value." % (repr(obj), 
attr))

if callable(current_object):
return current_object()

return current_object

if self.has_default():
return self.default
else:
return None

def prepare_template(self, obj):
"""
Flattens an object for indexing.

This loads a template
(``search/indexes/{app_label}/{model_name}_{field_name}.txt``) and
returns the result of rendering that template. ``object`` will be in
its context.
"""
if self.instance_name is None and self.template_name is None:
raise SearchFieldError("This field requires either its 
instance_name variable to be populated or an explicit template_name in 
order to load the correct template.")

if self.template_name is not None:
template_names = self.template_name

if not isinstance(template_names, (list, tuple)):
template_names = [template_names]
else:
app_label, model_name = get_model_ct_tuple(obj)
template_names = ['search/indexes/%s/%s_%s.txt' % (app_label, 
model_name, self.instance_name)]

t = loader.select_template(template_names)
return t.render(Context({'object': obj}))

def 

Re: Getting error: 'ascii' codec can't decode byte 0xc3 in position 1264: ordinal not in range(128)

2017-10-10 Thread Nicolas Ferrari
Hi, the issue is still present in the 3.0.x version.

Regards,

On Monday, October 2, 2017 at 11:11:17 PM UTC+2, Christian Hammond wrote:
>
> Hi Ali,
>
> We have a fix for this in our tree 
> (commit 23fbc2f28742442835c4c275e81c1ad0cb163ed6), which will be part of 
> the next 2.5.x release.
>
> Christian
>
> On Mon, Oct 2, 2017 at 7:05 AM, Ali Lokhandwala  > wrote:
>
>> Hi,
>> I am getting this error on our repo files when raising reviews post 
>> commit using:
>>
>> - root - Unable to update new review request from commit ID 
>> 949e6492ab2c243e8828c8329218089000a4da39 on repository ID=5: 'ascii' codec 
>> can't decode byte 0xc3 in position 1264: ordinal not in range(128)
>> Traceback (most recent call last):
>>   File 
>> "/opt/bitnami/apps/reviewboard/htdocs/reviewboard/reviews/managers.py", line 
>> 156, in create
>> draft.update_from_commit_id(commit_id)
>>   File 
>> "/opt/bitnami/apps/reviewboard/htdocs/reviewboard/reviews/models/review_request_draft.py",
>>  line 278, in update_from_commit_id
>> self.update_from_committed_change(commit_id)
>>   File 
>> "/opt/bitnami/apps/reviewboard/htdocs/reviewboard/reviews/models/review_request_draft.py",
>>  line 346, in update_from_committed_change
>> diff_file_contents=commit.diff.encode('utf-8'),
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1264: 
>> ordinal not in range(128)
>>
>> -- 
>> Supercharge your Review Board with Power Pack: 
>> https://www.reviewboard.org/powerpack/
>> Want us to host Review Board for you? Check out RBCommons: 
>> https://rbcommons.com/
>> Happy user? Let us know! https://www.reviewboard.org/users/
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "reviewboard" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to reviewboard...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Christian Hammond
> President/CEO of Beanbag 
> Makers of Review Board 
>

-- 
Supercharge your Review Board with Power Pack: 
https://www.reviewboard.org/powerpack/
Want us to host Review Board for you? Check out RBCommons: 
https://rbcommons.com/
Happy user? Let us know! https://www.reviewboard.org/users/
--- 
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Index failure after upgrade to ReviewBoard 2.5.16

2017-10-10 Thread Christian Hammond
Hmm, this is beyond bizarre. Note these lines:

if not hasattr(current_object, attr):
raise SearchFieldError("The model '%s' ('%s' -- %s) does not have a
model_attr '%s' (%s)." % (repr(obj), repr(current_object),
current_object.__class__.__name__, attr, hasattr(current_object, attr)))

The relevant parts are the if statement and the final argument to
SearchFieldError. Note how in the output, that final attribute resolves to
True, but the if statement resolves to False. It's the same exact check for
an attribute that is either there or not. It makes no sense for them to be
different. The attribute can't be gone in one statement and there in
another. So something truly bizarre appears to be happening, and I have no
idea what could possibly cause that. If it wasn't so consistent, I'd blame
the RAM on your system.

Just to gather more information, change the above code to;

print '%r (%s): %s' % (current_object, id(current_object),
hasattr(current_object, attr))
if not hasattr(current_object, attr):
import inspect
raise SearchFieldError("The model '%s' ('%s' -- %s.%s at %s --
%s:%s) does not have a model_attr '%s' (%s)." % (repr(obj),
repr(current_object), current_object.__class__.__module__,
current_object.__class__.__name__, inspect.getfile(obj.__class__), id(obj),
id(current_object), attr, hasattr(current_object, attr)))


We may be approaching a point in this where I won't be able to diagnose
much else over e-mail, and am basically out of ideas. We'd need to either
work directly on your system, set up a live session to diagnose it, or
provide a series of custom builds and gather confidential information, and
these require support contracts on our end. We'll see first if the above
tells us anything interesting.

Christian

On Tue, Oct 10, 2017 at 1:35 AM, 'Rob Backhurst' via reviewboard <
reviewboard@googlegroups.com> wrote:

> Here you go...
>
> # encoding: utf-8
> from __future__ import unicode_literals
>
> import re
>
> from django.template import Context, loader
> from django.utils import datetime_safe, six
>
> from haystack.exceptions import SearchFieldError
> from haystack.utils import get_model_ct_tuple
>
>
> class NOT_PROVIDED:
> pass
>
>
> DATETIME_REGEX = re.compile('^(?P\d{4})-(
> ?P\d{2})-(?P\d{2})(T|\s+)(?P\d{2}):(?P<
> minute>\d{2}):(?P\d{2}).*?$')
>
>
> # All the SearchFields variants.
>
> class SearchField(object):
> """The base implementation of a search field."""
> field_type = None
>
> def __init__(self, model_attr=None, use_template=False,
> template_name=None,
>  document=False, indexed=True, stored=True, faceted=False,
>  default=NOT_PROVIDED, null=False, index_fieldname=None,
>  facet_class=None, boost=1.0, weight=None):
> # Track what the index thinks this field is called.
> self.instance_name = None
> self.model_attr = model_attr
> self.use_template = use_template
> self.template_name = template_name
> self.document = document
> self.indexed = indexed
> self.stored = stored
> self.faceted = faceted
> self._default = default
> self.null = null
> self.index_fieldname = index_fieldname
> self.boost = weight or boost
> self.is_multivalued = False
>
> # We supply the facet_class for making it easy to create a faceted
> # field based off of this field.
> self.facet_class = facet_class
>
> if self.facet_class is None:
> self.facet_class = FacetCharField
>
> self.set_instance_name(None)
>
> def set_instance_name(self, instance_name):
> self.instance_name = instance_name
>
> if self.index_fieldname is None:
> self.index_fieldname = self.instance_name
>
> def has_default(self):
> """Returns a boolean of whether this field has a default value."""
> return self._default is not NOT_PROVIDED
>
> @property
> def default(self):
> """Returns the default value for the field."""
> if callable(self._default):
> return self._default()
>
> return self._default
>
> def prepare(self, obj):
> """
> Takes data from the provided object and prepares it for storage in
> the
> index.
> """
> # Give priority to a template.
> if self.use_template:
> return self.prepare_template(obj)
> elif self.model_attr is not None:
> # Check for `__` in the field for looking through the relation.
> attrs = self.model_attr.split('__')
> current_object = obj
>
> for attr in attrs:
> if not hasattr(current_object, attr):
> raise SearchFieldError("The model '%s' ('%s' -- %s) does not have a
> model_attr '%s' (%s)." % (repr(obj), repr(current_object),
> current_object.__class__.__name__, attr, hasattr(current_object, attr)))
>
>  

Re: Getting error: 'ascii' codec can't decode byte 0xc3 in position 1264: ordinal not in range(128)

2017-10-10 Thread Christian Hammond
That change did miss the release. It will be present in RC1.

Christian

On Tue, Oct 10, 2017 at 7:27 AM, Nicolas Ferrari 
wrote:

> Hi, the issue is still present in the 3.0.x version.
>
> Regards,
>
> On Monday, October 2, 2017 at 11:11:17 PM UTC+2, Christian Hammond wrote:
>>
>> Hi Ali,
>>
>> We have a fix for this in our tree (commit 
>> 23fbc2f28742442835c4c275e81c1ad0cb163ed6),
>> which will be part of the next 2.5.x release.
>>
>> Christian
>>
>> On Mon, Oct 2, 2017 at 7:05 AM, Ali Lokhandwala 
>> wrote:
>>
>>> Hi,
>>> I am getting this error on our repo files when raising reviews post
>>> commit using:
>>>
>>> - root - Unable to update new review request from commit ID 
>>> 949e6492ab2c243e8828c8329218089000a4da39 on repository ID=5: 'ascii' codec 
>>> can't decode byte 0xc3 in position 1264: ordinal not in range(128)
>>> Traceback (most recent call last):
>>>   File 
>>> "/opt/bitnami/apps/reviewboard/htdocs/reviewboard/reviews/managers.py", 
>>> line 156, in create
>>> draft.update_from_commit_id(commit_id)
>>>   File 
>>> "/opt/bitnami/apps/reviewboard/htdocs/reviewboard/reviews/models/review_request_draft.py",
>>>  line 278, in update_from_commit_id
>>> self.update_from_committed_change(commit_id)
>>>   File 
>>> "/opt/bitnami/apps/reviewboard/htdocs/reviewboard/reviews/models/review_request_draft.py",
>>>  line 346, in update_from_committed_change
>>> diff_file_contents=commit.diff.encode('utf-8'),
>>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1264: 
>>> ordinal not in range(128)
>>>
>>> --
>>> Supercharge your Review Board with Power Pack:
>>> https://www.reviewboard.org/powerpack/
>>> Want us to host Review Board for you? Check out RBCommons:
>>> https://rbcommons.com/
>>> Happy user? Let us know! https://www.reviewboard.org/users/
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "reviewboard" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to reviewboard...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Christian Hammond
>> President/CEO of Beanbag 
>> Makers of Review Board 
>>
> --
> Supercharge your Review Board with Power Pack:
> https://www.reviewboard.org/powerpack/
> Want us to host Review Board for you? Check out RBCommons:
> https://rbcommons.com/
> Happy user? Let us know! https://www.reviewboard.org/users/
> ---
> You received this message because you are subscribed to the Google Groups
> "reviewboard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to reviewboard+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Christian Hammond
President/CEO of Beanbag 
Makers of Review Board 

-- 
Supercharge your Review Board with Power Pack: 
https://www.reviewboard.org/powerpack/
Want us to host Review Board for you? Check out RBCommons: 
https://rbcommons.com/
Happy user? Let us know! https://www.reviewboard.org/users/
--- 
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.