Profile pictures cannot be found by catalog path

Bug #391146 reported by Jason Lantz
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KARL3
Fix Released
Low
Shane Hathaway

Bug Description

While working on the metadata extraction script for usage reporting, I ran into an error with using find_model on profile pictures using the path from the address_to_docid index of the catalog. The code below run in debug will highlight the problem. If you want to see the individual traceback, just remove the try/except.

>>> from repoze.bfg.traversal import find_model
>>> for path, docid in root.catalog.document_map.address_to_docid.items():
... try:
... obj = find_model(root, path)
... except:
... print 'Failed to find model at path: %s' % path
...
Failed to find model at path: /profiles/Anya%20Schiffrin/photo.jpg
Failed to find model at path: /profiles/Daniel%20Domagala/photo.jpg
Failed to find model at path: /profiles/David%20MacDonald/photo.jpg
...

Changed in karl3:
assignee: nobody → Chris Rossi (chris-archimedeanco)
importance: Undecided → Low
milestone: none → m21
Revision history for this message
Chris Rossi (chris-archimedeanco) wrote :

Rescheduled to this week.

Changed in karl3:
milestone: m21 → m22
Revision history for this message
Paul Everitt (paul-agendaless) wrote :

Let's hand this one over to Shane.

Changed in karl3:
assignee: Chris Rossi (chris-archimedeanco) → Shane Hathaway (shane-hathawaymix)
Changed in karl3:
milestone: m22 → m23
Revision history for this message
Shane Hathaway (shane-hathawaymix) wrote :

I believe these paths were caused by the fix_userids script when it was not updating the catalog's document_map. If so, we just need to pull out the old paths in debug mode.

Revision history for this message
Shane Hathaway (shane-hathawaymix) wrote :

The script below, which I tested on kdi-dev, will fix the issue. It turns out this problem still exists in the fix_userids script, so the long-term fix (if we need it) is to fix the fix_userids script.

def fix_photo_map():
    from repoze.bfg.traversal import model_path
    docid_to_address = root.catalog.document_map.docid_to_address
    address_to_docid = root.catalog.document_map.address_to_docid
    for profile in root['profiles'].values():
        for obj in profile.values():
            docid = getattr(obj, 'docid', None)
            if docid is not None:
                new_path = model_path(obj)
                old_path = docid_to_address.get(docid)
                if old_path != new_path:
                    docid_to_address[docid] = new_path
                    address_to_docid[new_path] = docid
                    print 'fixed %s' % new_path

def clean_document_map():
    docid_to_address = root.catalog.document_map.docid_to_address
    address_to_docid = root.catalog.document_map.address_to_docid
    for path, docid in list(address_to_docid.items()):
        correct_path = docid_to_address.get(docid)
        if path != correct_path:
            del address_to_docid[path]
            print 'removed %s' % path

fix_photo_map()
clean_document_map()
import transaction; transaction.commit()

Revision history for this message
Shane Hathaway (shane-hathawaymix) wrote :

... and then we need to run 'bin/reindex_catalog -p /profiles'.

Revision history for this message
Shane Hathaway (shane-hathawaymix) wrote :

Data fix applied on staging and in production on 2009 July 16.

Changed in karl3:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.