Code

Opened 5 years ago

Closed 4 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: patch
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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

Attachments (0)

Change History (7)

comment:1 Changed 5 years ago by Tobu

  • Keywords patch added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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:2 Changed 5 years ago by Tobu

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 Changed 4 years ago by russellm

  • Component changed from Uncategorized to GIS
  • Has patch set
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 4 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

(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 Changed 4 years ago by jbronn

(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 follow-up: Changed 4 years ago by ungenio

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:7 in reply to: ↑ 6 Changed 4 years ago by jbronn

  • Resolution set to worksforme
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.