Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local variable 'previous_obj' referenced before assignment #955

Closed
mindflayer opened this issue Jun 6, 2013 · 0 comments
Closed

local variable 'previous_obj' referenced before assignment #955

mindflayer opened this issue Jun 6, 2013 · 0 comments

Comments

@mindflayer
Copy link

In some cases 'previous_obj' will be referenced with no assignment at all:

https://github.com/toastdriven/django-tastypie/blob/master/tastypie/fields.py#L723

harishnsrinivas pushed a commit to harishnsrinivas/django-tastypie that referenced this issue Aug 31, 2014
SeanHayes added a commit that referenced this issue Feb 15, 2015
Added my name to the AUTHORS file for the bug fix #955
timurdaukaev added a commit to RevelSystems/django-tastypie that referenced this issue May 5, 2020
Merged commits from the original repo for v0.12.2 tag.

Note: I am going to squash it because I want to keep fork history simpler and to be able to track our own changes. And because I hope that eventually we will get rid of this fork (or even tastypie itself) at all. If you need an actual history - well, sorry.

Original commit messages:

* Get user model and username field in a more lazy way

User model will not be ready at import time

Signed-off-by: Ilya Baryshev <baryshev@gmail.com>

* Django 1.7: migrations

We're keeping old migrations in south_migrations folder to
be backwards-compatible with Django<1.7 and South>=1.0

* Django 1.7: Explicit fixtures in tests

Using of initial_data in tests is problematic due to new app loading mechanism.
Because initial_data fixtures is deprecated in favor of migrations, initial_data
fixtures are renamed (to avoid confusion).
They're explicitly specified in testcases.

* Django 1.7: Lazy loading of User model in management command

After app loading change, User model can no longer be referenced
while app registry is not populated.

This commit completes work in c7aa6c8

* Django 1.7: Fix ApiAccess __unicode__ for py3

* Django 1.7: Fix customuser tests

Due to app loading changes app_label is no longer effective,
so CustomUser model is redefined in tests.
Fixture name is changed to avoid collision with contrib.auth fixture

* Django 1.7: Update tox config

Update Django and django-oauth-plus versions

* Django 1.7: Minor testsuite fixes

* RuntimeError in related_resource, due to model name conflict
* ValueError when assigning to non-nullable field
* Add explicit MIDDLEWARE_CLASSES to avoid checks framework warnings

* Django 1.7: Fix PutListNestResouceValidationTestCase

Attribute 'pk' is ignored, use 'id' instead.
Due to non-monotonic autoincrement in sqlite prior 1.7 test was passing:
both notes were deleted and created anew (pk were not taken into account,
they just "fortunately" matched pks of newley created models).

* Fix for issue django-tastypie#955

* Added test case for the fix

* Removed incorrect import

* Django 1.7: Update tox to latest Django release

* Fixed test requirement for PyYAML. Thanks to AndrewGrossman for the report!

* find resource name using rfind

this fixes a bug where app name and resource name are the same.
/projects/api/v1/projects/1/ should return projects/1/ not projects/api/v1/projects/1/

* make sure we throw exception if not found

* add test

* Added release notes for v0.12.0.

* Bumped to 0.12.0!

* Starting next dev cycle.

* Enable syntax highlighting in README

* Update current version in README.rst

* Added 0.12.1 release notes.

* Bumped to v0.12.1! (posthumously, since I tagged the wrong commit)

* Starting the next dev cycle.

* pep8

* add failing test for prefetch_related resources

* update test

* fix bug by invalidating prefetch cache

* Update python3.rst

simple change from "Tastpie" to "Tastypie".

* Update serialization.rst

fixed typo

* Added my name to the AUTHORS file for the bug fix django-tastypie#955

* Django 1.8 compatibility

* Small optimization of `extract_credentials` method

Getting the header value for key `HTTP_AUTHORIZATION` only once for this method

* Django 1.8: requires SITE_ID in settings

* Django 1.8: update tarball location for 1.8

* Django 1.8: fixed core tests

* Django 1.8: fixed basic tests

* Django 1.8: fix for minor change in unset attributes of model objects

* Django 1.8: update travis config for one more env, disallow 1.7 and 1.8 failures

* Django 1.8: fixed related_resource tests.  I have no idea what I am doing.

* Django 1.8: whoops, no such env as 1.8+py2.6

* Django 1.8: removing not-implemented complex tests which break due to importing deleted comments app

* Last traces of complex.tests

* PUT response code correction

See commit for details

* Update PUT response codes

See commit for details: django-tastypie@abc0bef

* Update to django 1.8b1

* Changed html_theme to "classic" (from "default") to prevent Sphinx build error

* Update testenvs to use official Django 1.8 release

* Replace with python importlib 

Replace django.utils.importlib with python importlib 
"Warning: django.utils.importlib will be removed in Django 1.9"

* Replace with python importlib

Fix
Warning: django.utils.importlib will be removed in Django 1.9.

* Pinning version of mock as 1.1.0 and later no longer support python 2.6

Co-authored-by: Stefan Wehrmeyer <mail@stefanwehrmeyer.com>
Co-authored-by: Ilya Baryshev <baryshev@gmail.com>
Co-authored-by: harishn_knowlarity <harish.srinivas@eng.knowlarity.com>
Co-authored-by: harishn_knowlarity <me.harishn@gmail.com>
Co-authored-by: Daniel Lindsley <daniel@toastdriven.com>
Co-authored-by: Sam Kuehn <samkuehn@gmail.com>
Co-authored-by: Corey Farwell <coreyf@rwell.org>
Co-authored-by: Chris Adams <chris@improbable.org>
Co-authored-by: Jann Kleen <jann.kleen@freshx.de>
Co-authored-by: Eric Theise <erictheise@gmail.com>
Co-authored-by: Matthew Crowson <matthew.d.crowson@gmail.com>
Co-authored-by: George Dorn <georgedorn@gmail.com>
Co-authored-by: Willem Bult <willem.bult@gmail.com>
Co-authored-by: Chewey <prosto-chewey@users.noreply.github.com>
Co-authored-by: Seán Hayes <gasphynx@gmail.com>
Co-authored-by: Simon Kelly <skelly@dimagi.com>
Co-authored-by: Max Naude <maxnaude@gmail.com>
Co-authored-by: Renjith Thankachan <mail3renjith@gmail.com>
Co-authored-by: Sam Thompson <sam.thompson@buildingenergy.com>
timurdaukaev added a commit to RevelSystems/django-tastypie that referenced this issue May 6, 2020
Merged commits from the original repo for v0.13.3 tag.

Note: I am going to squash it because I want to keep fork history simpler and to be able to track our own changes. And because I hope that eventually we will get rid of this fork (or even tastypie itself) at all. If you need an actual history - well, sorry.

Original commit messages:

* Throttled requests now include Retry-After header.

* Added failing test case with extra data on a related field. Extra data directly on a parent recource is normally ignored.

* Extra data on related resources is now ignored.

* A more informative error message in Resource.put_list, and catch an error earlier in RelatedField.resource_from_uri.

* Made error in resource_from_uri more specific.

* Removed data shared on Field objects, changed code to reuse related resources.

* Use list comprehensions where reasonable, which is slightly faster.

* Added profilingtests.

* Get user model and username field in a more lazy way

User model will not be ready at import time

Signed-off-by: Ilya Baryshev <baryshev@gmail.com>

* Django 1.7: migrations

We're keeping old migrations in south_migrations folder to
be backwards-compatible with Django<1.7 and South>=1.0

* Django 1.7: Explicit fixtures in tests

Using of initial_data in tests is problematic due to new app loading mechanism.
Because initial_data fixtures is deprecated in favor of migrations, initial_data
fixtures are renamed (to avoid confusion).
They're explicitly specified in testcases.

* Django 1.7: Lazy loading of User model in management command

After app loading change, User model can no longer be referenced
while app registry is not populated.

This commit completes work in c7aa6c8

* Django 1.7: Fix ApiAccess __unicode__ for py3

* Django 1.7: Fix customuser tests

Due to app loading changes app_label is no longer effective,
so CustomUser model is redefined in tests.
Fixture name is changed to avoid collision with contrib.auth fixture

* Django 1.7: Update tox config

Update Django and django-oauth-plus versions

* Django 1.7: Minor testsuite fixes

* RuntimeError in related_resource, due to model name conflict
* ValueError when assigning to non-nullable field
* Add explicit MIDDLEWARE_CLASSES to avoid checks framework warnings

* Django 1.7: Fix PutListNestResouceValidationTestCase

Attribute 'pk' is ignored, use 'id' instead.
Due to non-monotonic autoincrement in sqlite prior 1.7 test was passing:
both notes were deleted and created anew (pk were not taken into account,
they just "fortunately" matched pks of newley created models).

* Fix for issue django-tastypie#955

* Added test case for the fix

* Removed incorrect import

* Django 1.7: Update tox to latest Django release

* Fixed test requirement for PyYAML. Thanks to AndrewGrossman for the report!

* find resource name using rfind

this fixes a bug where app name and resource name are the same.
/projects/api/v1/projects/1/ should return projects/1/ not projects/api/v1/projects/1/

* make sure we throw exception if not found

* add test

* Added release notes for v0.12.0.

* Bumped to 0.12.0!

* Starting next dev cycle.

* Enable syntax highlighting in README

* Update current version in README.rst

* Added 0.12.1 release notes.

* Bumped to v0.12.1! (posthumously, since I tagged the wrong commit)

* Starting the next dev cycle.

* pep8

* add failing test for prefetch_related resources

* update test

* fix bug by invalidating prefetch cache

* Update python3.rst

simple change from "Tastpie" to "Tastypie".

* Update serialization.rst

fixed typo

* Added my name to the AUTHORS file for the bug fix django-tastypie#955

* Django 1.8 compatibility

* Small optimization of `extract_credentials` method

Getting the header value for key `HTTP_AUTHORIZATION` only once for this method

* Django 1.8: requires SITE_ID in settings

* Django 1.8: update tarball location for 1.8

* Django 1.8: fixed core tests

* Django 1.8: fixed basic tests

* Django 1.8: fix for minor change in unset attributes of model objects

* Django 1.8: update travis config for one more env, disallow 1.7 and 1.8 failures

* Django 1.8: fixed related_resource tests.  I have no idea what I am doing.

* Django 1.8: whoops, no such env as 1.8+py2.6

* Django 1.8: removing not-implemented complex tests which break due to importing deleted comments app

* Last traces of complex.tests

* PUT response code correction

See commit for details

* Update PUT response codes

See commit for details: django-tastypie@abc0bef

* Test against latest django-oauth-plus from PyPI

* Update to django 1.8b1

* Changed html_theme to "classic" (from "default") to prevent Sphinx build error

* Update testenvs to use official Django 1.8 release

* Replace with python importlib 

Replace django.utils.importlib with python importlib 
"Warning: django.utils.importlib will be removed in Django 1.9"

* Replace with python importlib

Fix
Warning: django.utils.importlib will be removed in Django 1.9.

* Pinning version of mock as 1.1.0 and later no longer support python 2.6

* Bump version in README, note max django version.

* [doc] add missing imports in non-orm example

The example is still missing some but it's nice to show where `Resource` can be imported from.

* add import for Authorization

* Added my name to the AUTHORS file for django-tastypie#1311

* Upgrade to new Travis CI containers.

* Add code coverage collection.

* Cache pip dependencies.

* Added flake8 checking, moved doc builds to seperate matrix entry (no need to rebuild docs for each version of Django).

* Added myself to AUTHORS.

* Removed ApiField.value, which is unused and undocumented. It seems to be leftover from when field objects could store values and be serialized.

* Run `gis` tests in Spatialite on Travis CI.

* Fixed throttle tests to be deterministic.

* Fixing importlib error notification

TravisCI fix

* Switch order of check for callable and string.

This is necessary because in apply_sorting attribute can be only a
string, so by first checking for callable and then string in dehydrate,
one can define a callable string, which can then be used both in
dehydrate and apply_sorting.

* Reduces a query when looking up a user and another when comparing api keys.

* Allow creation of related resources that have an 'items' related_name

* Added mthornhill to Authors

* remove unimplemented to_html/from_html

* add to authors

* Performance improvements to Serializer.to_simple(), which gets called all the time. Got ResourceProfilingTestCase running in 14% less time.

* Added profilingtests.

* Reduced number of calls to callable() and other small fixes.

* Faster version of BaseThrottle.convert_identifier_to_key().

* dict_strip_unicode_keys now uses a list comprehension.

* Various performance improvements and code cleanup.

* Added tests for Serializer.to_simple().

* Removed obsolete Django 1.3/1.4 compatibility code (current minimum supported version is 1.5).

* Fixed git command, closes django-tastypie#840

* Styling fixes for tastypie.

* Styling fixes for tests.

* Line length and code complexity checking are optional, remaining checks are now mandatory. Styling fixes for docs/conf.py.

* Changes to make builds faster. Adds coverage to tests to make sure they're all being executed.

* If GEOS is not installed then exclude geos related calls.

* Added Travis CI, Coveralls, and PyPi badges

* Fixed PyPi badges, added new badges.

* Fixes Resource.deserialize() to honor format parameter - issue django-tastypie#1354

* Added test for issue django-tastypie#1354.

* More tests for Resource().get_via_uri().

* Raise ValueError when trying to register a Resource class instead of a Resource instance.

* Adding a test case to show that a related resource is correctly saved.

* Removed call to fk_resource.can_update(), since fk_resource.save() will the necessary object permissions checks (authorized_update_detail or authorized_create_detail). can_update() only checks the HTTP methods allowed, which doesn't really make sense for related resources. This fixes a bug (PR django-tastypie#1344) in otherwise updatable related resources which had PUT disabled. The bug caused the related resource to overwrite existing columns in the DB, since missing values were set to default since full hydration hadn't taken place.

Also includes changes to prevent saving bundles loaded via URI, and to make sure data is only saved inside Resource classes (replaced calls to obj_update() in RelatedField().resource_from_data()).

* Use Tastypie DateField for DateField on the model.

* Importing unicode_literals causes a problem in South when importing from django.db.models.fields because then the name of the model class that is passed into __import__ is unicode, rather than a byte string. I'm not quite sure why this causes a problem importing from this module but not others. However, removing the unicode_literals import from these migrations fixes the issue, and it doesn't look like the migrations have any literals that need to be unicode.

* Documentation fix for "Per-Request Alterations To the Queryset doesn't work as described django-tastypie#1352".

* Added failing test for embedded schemas.

* API consumers can now GET /api/v1/?fullschema=true to get all schemas in a single request.

* Updated flake8 commands to ignore Python files in hidden directories.

* Added failing test case when a non-null field is omitted.

* ApiFieldError is now raised when a not-null field is missing.

* New cookbook example for using resources in views with a valid 'resource_uri'

* Fixed cookbook for issue django-tastypie#962 ("Cookbook - Using Your Resource In Regular Views - incorrect example").

* Added verbose_name to API schema.

* Added more tests for Resource().get_via_uri() (django-tastypie#949).

* add test for reverse one to one saving.

* Add fix for django-tastypie#566 to ToOneField.

All tests pass.

* Started setup for doctesting our docs. (django-tastypie#1347)

* Fixes django-tastypie#1384

* Test for issue django-tastypie#1323.

* Fixes bug which occurs when whatever field detail_uri_name is (usually 'pk') has a default value. (Issue django-tastypie#1323)

* Reorder CI build matrix so that flake8 checks happen first.

* copy `same_origin` from django stable/1.8.x branch

* Change Django dev source URL to avoid pip error.

* Bumped Django versions, added testing for Django 1.9.

* Fixed disabling cache using timeout=0, appropriate unit tests added; fixes django-tastypie#1213, django-tastypie#1212

* Removed Django 1.5-1.6 support.

* Replaced reference to SingleRelatedObjectDescriptor for Django 1.9 compatibility.

* Replaced `get_caches` with `caches` for Django 1.9 support.

* Changes to make tests pass in Django 1.9.

* Updated README to correct version info.

* stop using django.conf.urls.patterns

* Fix for saving related items when resource_uri is provided but other unique data is not. (django-tastypie#1394)

* Release for v0.13.0. Added missing release notes for v0.12.2 (django-tastypie#1345).

* Updated old project URLs.

* Prevent muting non-django's exceptions (e.g. RequestException from 'requests' library). (Fixes django-tastypie#1297, from PR django-tastypie#1404)

* Added namespaces documentation.

* Add ResourceTestCaseMixin, deprecate ResourceTestCase.

* Added RTD link to README.

* Added error message when JSON requests cannot be deserialized

* Added tastypie to sys path in docs/conf.py.

* Updated docs to recommend StackOverflow instead of old Google Group.

* Updated/synced README and index.rst.

* Fix for flake8 failure.

* Move Content-Type from assertHttpAccepted

The assertion was in the wrong place. Rather than being in the tests
covering TastyPie, the Content-Type header assertion was in
`ResourceTestCase.assertHttpAccepted`.

* Fixed patch_detail not returning updated data. (Closes PR django-tastypie#1282)

* Added failing test for prefetch_related data during PATCH on a detail endpoint. (PR django-tastypie#1282)

* Fixed some doc formatting.

* Updated CONTRIBUTING docs.

* Gracefully handle UnsupportFormat exception

Return HTTP 400 from _handle_500 when handling an UnsupportedFormat
exception.

* Fixes django-tastypie#1413 - `obj_update` will take one more database search when bundle.obj.pk is an int value.

* Cleaned up tox and travis configs.

* Got rudimentary tests for the cookbook working. (django-tastypie#1347)

* Fix for issue django-tastypie#782 (django-tastypie#782)

Schema information only gives information about whether a related field is
'to_one' or 'to_many', but not about the actual resource type of the field. This
fix adds a new field, called 'related_schema' to the fields schema entry, which
defines the exact type of the related field:

    'user': {
        [..]
        'type': 'related'
        'related_type': 'to_one'
        'related_schema': '/api/v1/user/schema/'
        }

Changes by @juditnovak
Unit tests by @mikebryant

* Changed repr-value for Bundle to str in PY2

* Version bump for v0.13.1.

* Updated DjangoAuthorization to disallow read unless a user has `change` permission. (Closes django-tastypie#1407, PR django-tastypie#1409)

* Moved `detail_uri_kwargs` to Resource class. (Fixes django-tastypie#1431)

* Fixed doc theme change introduced in 8674d6b. Closes django-tastypie#1430.

* Disallow python-mimeparse==1.5 due to bug. Closes django-tastypie#1429.

* Authorization classes now handle usernames containing spaces. Closes django-tastypie#966.

* Fixed UnboundLocalError in lookup_kwargs_with_identifiers. Closes django-tastypie#942.

* Cleaned up old, unneeded code. (closes django-tastypie#1433)

Reuse Django test `Client.patch()`. (@SeanHayes, closes django-tastypie#1442)
Just a typo fix in the testing docs (by @bezidejni, closes django-tastypie#810)
Removed references to patterns() (by @SeanHayes, closes django-tastypie#1437)
Removed deprecated methods `Resource.apply_authorization_limits` and `Authorization.apply_limits` from code and documentation. (by @SeanHayes, closes django-tastypie#1383, django-tastypie#1045, django-tastypie#1284, django-tastypie#837)
Updates docs/cookbook.rst to make sure it's clear which `url` to import. (by @yuvadm, closes django-tastypie#716)
Updated docs/tutorial.rst. Without "null=True, blank=True" parameters in Slugfield, expecting "automatic slug generation" in save method is pointless. (by @orges, closes django-tastypie#753)
Cleaned up Riak docs. (by @SeanHayes, closes django-tastypie#275)
Include import statement for trailing_slash. (by @ljosa, closes django-tastypie#770)
Fix docs: `Meta.filtering` is actually a dict. (by @georgedorn, closes django-tastypie#807)
Fix load data command. (by @blite, closes django-tastypie#357, django-tastypie#358)

* Fix in `Resource.save_related`: `related_obj` can  be empty in patch requests (introduced in django-tastypie#1378). (Fixes django-tastypie#1436)

* Avoid modifying Field instances during request/response cycle. (closes django-tastypie#1415)

* Cleaned up self referential field handling.

* Removing the Manager dependency in ToManyField.dehydrate(). (Closes django-tastypie#537)

* Related schemas no longer raise error when not URL accessible. (Fixes PR django-tastypie#1439)

* Updated release notes.

* Fixed bug that prevented fitlering on related resources. `apply_filters` hook now used in obj_get. (Fixes django-tastypie#1435, Fixes django-tastypie#1443)

* Use `build_filters` in `obj_get`. (Fixes django-tastypie#1444)

* Test for django-tastypie#1446 which was fixed in af2c1d6. (Closes django-tastypie#1446)

* Updating for v0.13.2 release.

* Permit changing existing value on a ToOneField to None. (Closes django-tastypie#1449)

* Updating for v0.13.3 release.

Co-authored-by: Sean Hayes <sean@seanhayes.name>
Co-authored-by: Stefan Wehrmeyer <mail@stefanwehrmeyer.com>
Co-authored-by: Ilya Baryshev <baryshev@gmail.com>
Co-authored-by: harishn_knowlarity <harish.srinivas@eng.knowlarity.com>
Co-authored-by: harishn_knowlarity <me.harishn@gmail.com>
Co-authored-by: Daniel Lindsley <daniel@toastdriven.com>
Co-authored-by: Sam Kuehn <samkuehn@gmail.com>
Co-authored-by: Corey Farwell <coreyf@rwell.org>
Co-authored-by: Chris Adams <chris@improbable.org>
Co-authored-by: Jann Kleen <jann.kleen@freshx.de>
Co-authored-by: Eric Theise <erictheise@gmail.com>
Co-authored-by: Matthew Crowson <matthew.d.crowson@gmail.com>
Co-authored-by: George Dorn <georgedorn@gmail.com>
Co-authored-by: Willem Bult <willem.bult@gmail.com>
Co-authored-by: Chewey <prosto-chewey@users.noreply.github.com>
Co-authored-by: Seán Hayes <gasphynx@gmail.com>
Co-authored-by: Simon Kelly <skelly@dimagi.com>
Co-authored-by: Max Naude <maxnaude@gmail.com>
Co-authored-by: Renjith Thankachan <mail3renjith@gmail.com>
Co-authored-by: Sam Thompson <sam.thompson@buildingenergy.com>
Co-authored-by: Nik Nyby <nnyby@columbia.edu>
Co-authored-by: Renjith Thankachan <sideffect0@users.noreply.github.com>
Co-authored-by: Jelena Kutalovskaja <jelena.kutalovskaja@gmail.com>
Co-authored-by: Mitar <mitar.git@tnode.com>
Co-authored-by: mick <michael@maithu.com>
Co-authored-by: Fedor Baart <fedor.baart@deltares.nl>
Co-authored-by: Phoebe B <phoebebright310@gmail.com>
Co-authored-by: Patrick Hagemeister <patrick@krankikom.de>
Co-authored-by: annacorobco <anna.corobco@gmail.com>
Co-authored-by: strets123 <strets123@gmail.com>
Co-authored-by: Alexey Kotlyarov <alexey@infoxchange.net.au>
Co-authored-by: Ben Demboski <bend@meevine.com>
Co-authored-by: Simon Ye <sye737@gmail.com>
Co-authored-by: yuri <yuri.govor@gmail.com>
Co-authored-by: Charpentier Johan <jcharpentier@bearstech.com>
Co-authored-by: David Hatch <dhatch387@gmail.com>
Co-authored-by: Guilhem Saurel <guilhem.saurel@gmail.com>
Co-authored-by: Vsevolod Novikov <nnseva@gmail.com>
Co-authored-by: Brad Pitcher <bradpitcher@gmail.com>
Co-authored-by: Alexey Subbotin <dotsbb@gmail.com>
Co-authored-by: Eleni Lixourioti <contact@eleni.co>
Co-authored-by: Jack Cushman <jcushman@gmail.com>
Co-authored-by: John Lucas <john.lucas845@gmail.com>
Co-authored-by: Matt Briancon <matt.briancon@gmail.com>
Co-authored-by: Miguel Gonzalez <scenting@gmail.com>
Co-authored-by: Mike Bryant <m@ocado.com>
Co-authored-by: Maxim Filipenko <proktusfahitasiv@gmail.com>
Co-authored-by: Thomas @ BeeDesk <thomas@beedesk.com>
Co-authored-by: J. Javier Maestro <jjmaestro@twoapart.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant