Opened 15 years ago

Closed 15 years ago

Last modified 9 years ago

#11353 closed (worksforme)

use sphinx autodoc directives on geodjango application

Reported by: yml Owned by: nobody
Component: GIS Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: no UI/UX: no

Description

I am trying to generate the API documentation of django-geotagging
[1]. django-geotagging is a django application. I would like to add to
the existing documentation rst files some "automatically" generated API documentation.
In order to do this I have added a file called : api.rst which look
like this : http://dpaste.com/58306/

when I run the this command:

sphinx-build -a -b html .  _build

I get this error message :

Exception occurred:[ 20%] api
  File "/usr/lib/python2.6/django/contrib/gis/db/models/proxy.py", line 27, in __get__
    geom_value = obj.__dict__[self._field.attname]
AttributeError: 'NoneType' object has no attribute '__dict__'
The full traceback has been saved in /tmp/sphinx-err-k0o7j2.log, if you want to report the issue to the author.

Changing the line 27 from :

geom_value = obj.__dict__[self._field.attname]

to :

        try:
            geom_value = obj.__dict__[self._field.attname] 
        except:
            geom_value = None

seems to fix this issue. After this modification I can use autodoc however I am not sure if this is not breaking something else or only hiding the problem.

ps : I have described this behavior on this post [2]
[1] https://code.launchpad.net/~yml/django-geotagging/geotags/+merges
[2]http://groups.google.com/group/sphinx-dev/browse_thread/thread/7f0e83b3a2775d4

Change History (6)

comment:2 by Tobu, 15 years ago

This is the descriptor protocol, documented at http://docs.python.org/reference/datamodel.html#descriptors .

The bug in the current implementation is that it only works on instance access, and not class access.

This is easy to fix, add this to the beginning of the get method:

        if obj is None:
            # Accessed on a class, not an instance
            return self 

comment:3 by Russell Keith-Magee, 15 years ago

Component: UncategorizedGIS
Has patch: set
Triage Stage: UnreviewedAccepted

The 'if obj is None' approach suggested by Tobu looks like the right approach here, and is consistent with the way the descriptor protocol is handled for related fields.

comment:4 by jbronn, 15 years ago

Resolution: fixed
Status: newclosed

(In [12584]) Fixed #11353 -- GeometryProxy descriptor no longer chokes when accessed from a class rather than an instance, thanks yml and Tobu; removed unnecessary imports from types and cleaned up whitespace.

comment:5 by jbronn, 15 years ago

(In [12585]) [1.1.X] Fixed #11353 -- GeometryProxy descriptor no longer chokes when accessed from a class rather than an instance, thanks yml and Tobu; removed unnecessary imports from types and cleaned up whitespace.

Backport of r12584 from trunk.

comment:6 by David Bennett, 15 years ago

Resolution: fixed
Status: closedreopened

This patch has introduced an error for me when doing a query on a Point field:

Traceback:
File "c:\development\workspace\django\src\django-trunk\django\core\handlers\base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "C:\Development\workspace\django\crossfitfind\apps\locator\sites.py" in index
  148.                                            self.geo_latlng: False}
File "c:\development\workspace\django\src\django-trunk\django\db\models\manager.py" in filter
  141.         return self.get_query_set().filter(*args, **kwargs)
File "c:\development\workspace\django\src\django-trunk\django\db\models\query.py" in filter
  545.         return self._filter_or_exclude(False, *args, **kwargs)
File "c:\development\workspace\django\src\django-trunk\django\db\models\query.py" in _filter_or_exclude
  563.             clone.query.add_q(Q(*args, **kwargs))
File "c:\development\workspace\django\src\django-trunk\django\db\models\sql\query.py" in add_q
  1100.                             can_reuse=used_aliases)
File "c:\development\workspace\django\src\django-trunk\django\db\models\sql\query.py" in add_filter
  995.                     negate=negate, process_extras=process_extras)
File "c:\development\workspace\django\src\django-trunk\django\db\models\sql\query.py" in setup_joins
  1163.                             "Choices are: %s" % (name, ", ".join(names)))

Exception Type: FieldError at /
Exception Value: Cannot resolve keyword '<django.contrib.gis.db.models.proxy.GeometryProxy object at 0x03E98410>' into field.

Changing the conditional to return None instead of self seems to solve the problem:

        if obj is None:
            # Accessed on a class, not an instance
            return None

in reply to:  6 comment:7 by jbronn, 15 years ago

Resolution: worksforme
Status: reopenedclosed

Replying to ungenio:

This patch has introduced an error for me when doing a query on a Point field:

What does the query look like? Providing a traceback without context on how to reproduce is not enough to open this ticket. Please provide an example model, data, and queryset invocation that makes it possible for others to recreate the error on their own -- until then, I'm closing as works for me.

Note: See TracTickets for help on using tickets.
Back to Top