[Zope-CMF] why portal_catalog collect "None" object ?

GC gc@iis.sinica.edu.tw
Wed, 19 Mar 2003 12:22:56 +0800


# script   :   CPS_meta_type=3D'Document'
#                 review_state =3D ['published', 'visible']
entries =3D
  context.portal_catalog(portal_type =3D CPS_meta_type,
                                   review_state =3D review_state,
                                   sort_on =3D 'Counter',
                                   sort_order =3D "reverse")
urlList =3D []
for entry in entries
    urlList.append(entry.getObject().absolute_url())

return urlList


#
#  This script will fail if entry is happened to be None
#  Thus=20
#      if entry !=3D None:
#  must be inserted before the list append operation ..
#  But what I am woundered that why portal_catalog
#  collects some None objects ??!!
#  This is my first problem

I have to write the following code to solve the second problem
# script:  id=3DNone
try:
  objs =3D context.portal_catalog(id=3Did)
  #return objs[0]  # <--  not work well
  #return the object with min length absolute_url
  min_len =3D len(objs[0].getObject().absolute_url())
  n=3Dlen(objs)
  #print objs[0].getObject().absolute_url()
  idx=3D0;
  if n>1:
    for i in range(n)[1:]:
      tmp_len =3D len(objs[i].getObject().absolute_url())
      if tmp_len < min_len:
        idx =3D i
        min_len=3Dtmp_len
  return objs[idx]
except:
  return None

# as you've seen, for the given id, I return the object with shortest
# URL string length
# But why portal_catalog collects many objects for an id ?

=A2=E2=A2=F0=A3A
=A2=D4=A2=FA=A2=F7=A2=F5=A1@=A2=D5=A2=D1





-----Original Message-----
From: Dieter Maurer [mailto:dieter@handshake.de]=20
Sent: Wednesday, March 19, 2003 5:38 AM
To: GC
Cc: zope-cmf@zope.org
Subject: Re: [Zope-CMF] why portal_catalog collect "None" object ?


GC wrote at 2003-3-18 18:17 +0800:
 >    I use this code within a python script of my CMF site
 >=20
 >             entries =3D context.portal_catalog(portal_type =3D
 > CPS_meta_type,
 >                                          review_state =3D =
public_state,
 >                                          sort_on =3D 'Counter',
 >                                          sort_order =3D "reverse")
 >=20
 >    Amazingly, it collect also the "deleted" object, such that my page
 > template form got an error
 >    caused from
 >          "None" object can not apply getObject() method !!
 >=20
 >    Why these ghost objects still be collected by portal_catalog ?
 >    How can I avoid this ?

The code you show us does not contain "getObject"...

Obviously, the cited error message does not relate to the above code
snippet.

Come back again with the correct one.

 >     Another weird problem about my portal_catalog is that
 >=20
 >     it collect redundant object objects with recursive path that are
 > identical to the same object !
 >     For example :
 >=20
 >     I got a list of objects with the following url
 >=20
 >        http://gc:88/
 >=20
 > =20
 >
http://gc:88/Members/john/Dumbell_Covering_Problem/Plone/Members/john/Du
 > mbell_Covering_Problem
 >=20
 > =20
 >
http://gc:88/Members/john/Dumbell_Covering_Problem/Plone/Members/john/Du
 > mbell_Covering_Problem/Plone/Members/john/Dumbell_Covering_Problem
 >=20
 >        ...
 >=20
 >      My Goodness !

Indeed!

Usually, the catalog uses "getPhysicalPath" to derive an uid for an
object. The application can pass in a different uid. As you see, your
application did....


Dieter