Commit Graph

1550 Commits

Author SHA1 Message Date
Claude Paroz 45edb9d235 Fixed #22057 -- Ensured reverse_lazy can be used in settings
And without causing a circular import. Thanks Akis Kesoglou for
the report.
2014-02-18 10:23:30 +01:00
Artur Frysiak faf6a911ad Fixed #22023 -- Raised an error for values() followed by defer() or only().
Previously, doing so resulted in invalid data or crash.

Thanks jtiai for the report and Karol Jochelson,
Jakub Nowak, Loic Bistuer, and Baptiste Mispelon for reviews.
2014-02-17 14:46:13 -05:00
Christopher Medrela d0133504e5 Fixed #22047 -- detecting related_name clash with inheritance
Thanks to mondone for fruitful colaboration.
2014-02-15 17:24:05 +01:00
Albert Wang 8bbdcc76e4 Fixed #19299 -- Fixed Nullification of Foreign Keys To CharFields
Thanks tunixman for the report and Baptiste Mispelon and
Shai Berger for reviews.
2014-02-15 09:47:32 -05:00
Christopher Adams eefc88feef Fixed #2445 -- Allowed limit_choices_to attribute to be a callable.
ForeignKey or ManyToManyField attribute ``limit_choices_to`` can now
be a callable that returns either a ``Q`` object or a dict.

Thanks michael at actrix.gen.nz for the original suggestion.
2014-02-11 14:05:12 -05:00
Christopher Medrela ee9fcb1672 Fixed #17673 -- Forbid field shadowing.
Thanks Anssi Kääriäinen for the suggestion.
2014-02-10 10:04:19 -05:00
Robert Stapenhurst 12385a5f86 Fixed #21763 -- Added an error msg for missing methods on ManyRelatedManager.
Attempting to add() and remove() an object related by a 'through' model
now raises more descriptive AttributeErrors, in line with set and
create().
2014-02-09 16:01:17 -05:00
Loic Bistuer 8847a0c601 Fixed #16192 -- Made unique error messages in ModelForm customizable.
Overriding the error messages now works for both unique fields, unique_together
and unique_for_date.

This patch changed the overriding logic to allow customizing NON_FIELD_ERRORS
since previously only fields' errors were customizable.

Refs #20199.

Thanks leahculver for the suggestion.
2014-02-08 04:59:09 -05:00
Anssi Kääriäinen 35cecb1ebd Fixed #21748 -- join promotion for negated AND conditions
Made sure Django treats case .filter(NOT (a AND b)) the same way as
.filter((NOT a OR NOT b)) for join promotion.
2014-02-04 18:48:06 +02:00
Alex Gaynor 5616234d4d Removed an unused import which snuck in. 2014-02-02 12:14:16 -08:00
Michael Manfre 3ffeb93186 Ensure cursors are closed when no longer needed.
This commit touchs various parts of the code base and test framework. Any
found usage of opening a cursor for the sake of initializing a connection
has been replaced with 'ensure_connection()'.
2014-02-02 12:47:21 -05:00
Michael Manfre 0837eacc4e Made SQLCompiler.execute_sql(result_type) more explicit.
Updated SQLUpdateCompiler.execute_sql to match the behavior described in
the docstring; the 'first non-empty query' will now include all queries,
not just the main and first related update.

Added CURSOR and NO_RESULTS result_type constants to make the usages more
self documenting and allow execute_sql to explicitly close the cursor when
it is no longer needed.
2014-02-02 12:47:06 -05:00
Anssi Kääriäinen 0ca647357e Fixed #21883 -- Added six.moves.xrange import
When moving code around from sql.where to lookups six.moves.xrange
import was forgotten. The xrange import is needed on Python 3.
2014-01-28 21:08:37 +02:00
Loic Bistuer 3e4dc5ecf2 Fixed #21853 -- Fixed Manager.__module__ to properly return 'django.db.models.manager'.
The combination of BaseManager.from_queryset() and RenameMethodsBase results in
Manager.__module__ having the wrong value. This can be an issue when trying to
pickle the Manager class.
2014-01-28 08:17:01 -05:00
Aymeric Augustin 4f03b718f7 Fixed #21877 -- Renamed django.apps.base to config. 2014-01-26 13:17:03 +01:00
Aymeric Augustin f901b4d6c8 Took advantage of the new get_model API. Refs #21702. 2014-01-26 13:08:05 +01:00
Andrew Godwin f5f556dba3 Unroll choices iterators in field deconstruction 2014-01-25 00:23:28 +00:00
Anssi Kääriäinen 78a2617703 Fixed #21787 -- regression in MTI .exclude() queries 2014-01-24 10:10:17 +02:00
Anssi Kääriäinen 1c360dbbf5 Use date_extract_sql() for DateFields
Refs #21821
2014-01-20 10:52:58 +02:00
Anssi Kääriäinen b86321e9a4 Fixed regex lookup on Oracle
Refs #21821
2014-01-20 10:52:58 +02:00
Anssi Kääriäinen a9f1711518 Fixed Oracle in lookup when more than 1000 params
Refs #21821.
2014-01-20 10:52:57 +02:00
Russell Keith-Magee a029efca44 Removed an inactive system check for upload_to.
Thanks to Simon Charette for the eagle eyes.
2014-01-20 12:31:35 +08:00
Alex Gaynor be8173af51 Fixed a small collection of flake8 violations that had snuck in 2014-01-19 21:15:31 -06:00
Russell Keith-Magee d818e0c9b2 Fixed #16905 -- Added extensible checks (nee validation) framework
This is the result of Christopher Medrela's 2013 Summer of Code project.

Thanks also to Preston Holmes, Tim Graham, Anssi Kääriäinen, Florian
Apolloner, and Alex Gaynor for review notes along the way.

Also: Fixes #8579, fixes #3055, fixes #19844.
2014-01-20 10:45:21 +08:00
Andrew Godwin 3f1a008266 Fixed #21664: Multi-table inheritance was duplicating _ptr fields 2014-01-19 18:35:49 +00:00
Andrew Godwin c9de1b4a55 Implement swappable model support for migrations 2014-01-19 16:43:12 +00:00
Anssi Kääriäinen 994c842bc9 Fixed Oracle query failures caused by lookup refactor
Refs #21821.
2014-01-19 10:09:17 +02:00
Anssi Kääriäinen f468662e24 Fixed #21821 -- db_type argument for field_cast_sql
The db_type argument for connection.ops.field_cast_sql wasn't correctly
set after merge of custom lookups patch.
2014-01-18 21:18:50 +02:00
Aymeric Augustin 2f65b8e14c Fixed #21794 -- Adjusted warning for abstract models.
As far as I can tell, they don't need an app_label.

Thanks Simon Charette for the report and the review.
2014-01-18 18:23:13 +01:00
Anssi Kääriäinen 20bab2cf9d Fixed #16187 -- refactored ORM lookup system
Allowed users to specify which lookups or transforms ("nested lookus")
are available for fields. The implementation is now class based.

Squashed commit of the following:

commit fa7a7195f1
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 18 10:53:24 2014 +0200

    Added lookup registration API docs

commit eb1c8ce164
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Tue Jan 14 18:59:36 2014 +0200

    Release notes and other minor docs changes

commit 11501c29c9
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Jan 12 20:53:03 2014 +0200

    Forgot to add custom_lookups tests in prev commit

commit 83173b960e
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Jan 12 19:59:12 2014 +0200

    Renamed Extract -> Transform

commit 3b18d9f3a1
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Jan 12 19:51:53 2014 +0200

    Removed suggestion of temporary lookup registration from docs

commit 21d0c7631c
Merge: 2509006 f2dc442
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Jan 12 09:38:23 2014 -0800

    Merge pull request #2 from mjtamlyn/lookups_3

    Reworked custom lookups docs.

commit f2dc4429a1
Author: Marc Tamlyn <marc.tamlyn@gmail.com>
Date:   Sun Jan 12 13:15:05 2014 +0000

    Reworked custom lookups docs.

    Mostly just formatting and rewording, but also replaced the example
    using ``YearExtract`` to  use an example which is unlikely to ever be
    possible directly in the ORM.

commit 2509006506
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Jan 12 13:19:13 2014 +0200

    Removed unused import

commit 4fba5dfaa0
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 22:34:41 2014 +0200

    Added docs to index

commit 6d53963f37
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 22:10:24 2014 +0200

    Dead code removal

commit f9cc039007
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 19:00:43 2014 +0200

    A new try for docs

commit 33aa18a6e3
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 14:57:12 2014 +0200

    Renamed get_cols to get_group_by_cols

commit c7d5f8661b
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 14:45:53 2014 +0200

    Altered query string customization for backends vendors

    The new way is trying to call first method 'as_' + connection.vendor.
    If that doesn't exist, then call as_sql().

    Also altered how lookup registration is done. There is now
    RegisterLookupMixin class that is used by Field, Extract and
    sql.Aggregate. This allows one to register lookups for extracts and
    aggregates in the same way lookup registration is done for fields.

commit 90e7004ec1
Merge: 66649ff f7c2c0a
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 13:21:01 2014 +0200

    Merge branch 'master' into lookups_3

commit 66649ff891
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Jan 11 13:16:01 2014 +0200

    Some rewording in docs

commit 31b8faa627
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Dec 29 15:52:29 2013 +0200

    Cleanup based on review comments

commit 1016159f34
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Dec 28 18:37:04 2013 +0200

    Proof-of-concept fix for #16731

    Implemented only for SQLite and PostgreSQL, and only for startswith
    and istartswith lookups.

commit 193cd097ca
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Dec 28 17:57:58 2013 +0200

    Fixed #11722 -- iexact=F() produced invalid SQL

commit 08ed3c3b49
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Dec 21 23:59:52 2013 +0200

    Made Lookup and Extract available from django.db.models

commit b99c8d83c9
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Dec 21 23:06:29 2013 +0200

    Fixed review notes by Loic

commit 049eebc070
Merge: ed8fab7 b80a835
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Dec 21 22:53:10 2013 +0200

    Merge branch 'master' into lookups_3

    Conflicts:
    	django/db/models/fields/__init__.py
    	django/db/models/sql/compiler.py
    	django/db/models/sql/query.py
    	tests/null_queries/tests.py

commit ed8fab7fe8
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Dec 21 22:47:23 2013 +0200

    Made Extracts aware of full lookup path

commit 27a57b7aed
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Dec 1 21:10:11 2013 +0200

    Removed debugger import

commit 074e0f5aca
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Dec 1 21:02:16 2013 +0200

    GIS lookup support added

commit 760e28e72b
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Dec 1 20:04:31 2013 +0200

    Removed usage of Constraint, used Lookup instead

commit eac4776684
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Dec 1 02:22:30 2013 +0200

    Minor cleanup of Lookup API

commit 2adf50428d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sun Dec 1 02:14:19 2013 +0200

    Added documentation, polished implementation

commit 32c04357a8
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Nov 30 23:10:15 2013 +0200

    Avoid OrderedDict creation on lookup aggregate check

commit 7c8b3a32cc
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Sat Nov 30 23:04:34 2013 +0200

    Implemented nested lookups

    But there is no support of using lookups outside filtering yet.

commit 4d219d4cde
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date:   Wed Nov 27 22:07:30 2013 +0200

    Initial implementation of custom lookups
2014-01-18 11:46:19 +02:00
Andrew Godwin 86e69bf3b6 Fixed #21785: Bad handling of both auto_now and _add on deconstruct 2014-01-17 10:46:03 +00:00
Aymeric Augustin d562527a16 Fixed #21477 -- Renamed db to using in pre/post_migrate signals. 2014-01-12 22:24:33 +01:00
Anssi Kääriäinen 9918c11114 Fixed #21413 -- resolve_columns fields misalignment 2014-01-12 18:07:39 +02:00
Aymeric Augustin 3326a412cc Deprecated importing a model before loading its application.
Refs #21719, #21680.
2014-01-10 23:43:10 +01:00
maurycyp 0423e0796a Changed parent class calls to super in Field subclasses 2014-01-08 06:54:37 -05:00
Aymeric Augustin f630373b92 Fixed #21711 -- Enforced unicity of model names. 2014-01-05 20:52:53 +01:00
Aymeric Augustin c40209dcc0 Made it possible to change an application's label in its configuration.
Fixed #21683.
2013-12-31 17:30:58 +01:00
Aymeric Augustin 75220d3b5d Small style cleanup. 2013-12-31 16:24:40 +01:00
Aymeric Augustin 80004c7cc0 Turned django.db.models.app_cache_ready back into a method.
Thanks Anssi for noticing this mistake in a refactoring.
2013-12-31 15:27:25 +01:00
Aymeric Augustin 80d74097b4 Stopped populating the app registry as a side effect.
Since it triggers imports, it shouldn't be done lightly.

This commit adds a public API for doing it explicitly, django.setup(),
and does it automatically when using manage.py and wsgi.py.
2013-12-30 22:11:17 +01:00
Aymeric Augustin 20d487c27b Replaced Options.object_name.lower() by Options.model_name.
Thanks Simon for the suggestion.

Also removed inappropriate lowercasing of app labels in migrations.
Unlike model names, they are case sensitive.
2013-12-29 18:48:37 +01:00
Aymeric Augustin 00110904ac Refactored the migration signals to use app configs.
De-aliased pre/post_syncdb to pre/post_migrate to increase
backwards-compatibility.
2013-12-29 17:53:42 +01:00
Aymeric Augustin 9f13c33281 Removed the only_installed argument of Apps.get_models.
Refs #15903, #15866, #15850.
2013-12-28 20:54:26 +01:00
Aymeric Augustin ba7206cd81 Changed get_model to raise an exception on errors.
Returning None on errors required unpythonic error checking and was
inconsistent with get_app_config.

get_model was a private API until the previous commit, but given that it
was certainly used in third party software, the change is explained in
the release notes.

Applied the same change to get_registered_model, which is a new private
API introduced during the recent refactoring.
2013-12-28 20:53:00 +01:00
Aymeric Augustin 81354b82bf Stopped calling apps.get_model with only_installed=False.
ContentTypes are only created for installed applications, and I could
make a case for not returning a model that isn't installed any more.
The check for stale ContentTypes in update_contenttypes doesn't use
model_class.

ModelSignal actually needs get_registered_model since the lookup happens
at import time. I took this opportunity to perform a small refactoring.
2013-12-28 20:42:58 +01:00
Aymeric Augustin 52325b0a04 Turned apps.ready into a property. Added tests. 2013-12-26 15:04:58 +01:00
Aymeric Augustin 8f04f53dd8 Removed a few gratuitous lambdas. 2013-12-26 14:03:50 +01:00
Jonas Gastal 96967f642f Typo fix for exception message. 2013-12-24 14:26:50 -02:00
Aymeric Augustin 1716b7ce5a Renamed AppCache to Apps.
Also renamed app_cache to apps and "app cache" to "app registry".

Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
2013-12-24 12:25:17 +01:00
Aymeric Augustin 17c66e6fe7 Renamed has_model to get_registered_models.
That matches its return type better.
2013-12-22 17:08:17 +01:00
Aymeric Augustin 2fef9e5375 Moved apps back in the toplevel django namespace.
Reverted 4a56a93cc4.
2013-12-22 11:39:55 +01:00
Aymeric Augustin 70c9654d45 Renamed registered_model to has_model.
This avoids possible confusion with register_model.

Thanks Marc Tamlyn for the suggestion.
2013-12-22 11:39:18 +01:00
Aymeric Augustin 439b364e1e Added an _-prefix to pending lookups because it's transient. 2013-12-22 11:39:17 +01:00
Aymeric Augustin 86804ab063 Terminated AppCache._populate() with extreme prejudice.
It was called _populate() before I renamed it to populate(). Since it
has been superseded by populate_models() there's no reason to keep it.

Removed the can_postpone argument of load_app() as it was only used by
populate(). It's a private API and there's no replacement. Simplified
load_app() accordingly. Then new version behaves exactly like the old
one even though it's much shorter.
2013-12-22 11:39:17 +01:00
Aymeric Augustin 9b3389b726 Removed the app_config.installed flag.
Since applications that aren't installed no longer have an application
configuration, it is now always True in practice.

Provided an abstraction to temporarily add or remove applications as
several tests messed with app_config.installed to achieve this effect.
For now this API is _-prefixed because it looks dangerous.
2013-12-22 11:39:17 +01:00
Aymeric Augustin 742ed9878e Refactored registration of models.
Got rid of AppConfig._stub. As a side effect, app_cache.app_configs now
only contains entries for applications that are in INSTALLED_APPS, which
is a good thing and will allow dramatic simplifications (which I will
perform in the next commit). That required adjusting all methods that
iterate on app_configs without checking the "installed" flag, hence the
large changes in get_model[s].

Introduced AppCache.all_models to store models:
- while the app cache is being populated and a suitable app config
  object to register models isn't available yet;
- for applications that aren't in INSTALLED_APPS since they don't have
  an app config any longer.

Replaced get_model(seed_cache=False) by registered_model() which can be
kept simple and safe to call at any time, and removed the seed_cache
argument to get_model[s]. There's no replacement for that private API.

Allowed non-master app caches to go through populate() as it is now
safe to do so. They were introduced in 1.7 so backwards compatibility
isn't a concern as long as the migrations framework keeps working.
2013-12-22 11:39:17 +01:00
Alexey Voronov 7f2485b4d1 Fixed #21643 -- repeated execution of qs with F() + timedelta
Thanks Tim Graham for review.
2013-12-22 00:03:17 +02:00
Baptiste Mispelon f1b3ab9c21 Fixed #11629 -- Deprecated callable arguments to queryset methods.
Callable arguments were an untested and undocumented feature.
2013-12-18 18:40:00 +01:00
Denis Moskalets d4e578d0f6 Fixed #21552 -- Allowed the use of None for the iexact lookup.
Thanks Anubhav Joshi for the documentation.
2013-12-18 09:34:53 -05:00
Aymeric Augustin 7eea9bf303 Normalized Model._meta.installed.
Used the information from the app cache instead of creating a duplicate
based on INSTALLED_APPS.

Model._meta.installed is no longer writable. It was a rather sketchy way
to alter private internals anyway.
2013-12-17 21:55:16 +01:00
Aymeric Augustin 4a56a93cc4 Moved the new app cache inside core. 2013-12-17 10:17:46 +01:00
Aymeric Augustin b3d5efe23f Restored deprecated aliases for functions in django.db.models.
Thanks Marc Tamlyn for the suggestion.
2013-12-17 10:17:46 +01:00
Aymeric Augustin d44de9b933 Removed the _-prefix for populate().
Several parts of Django call get_apps() with a comment along this lines
of "this has the side effect of calling _populate()". I fail to see how
this is better than just calling populate()!
2013-12-17 10:17:45 +01:00
Aymeric Augustin ebda5800ae Simplified register_models.
Since it's never called with more than one model at a time the current
signature is needlessly complicated.
2013-12-17 10:17:45 +01:00
Aymeric Augustin 2c9e84af4a Removed unused attribute app_errors of the app cache.
get_app_errors() always returned an empty dictionary; this behavior is
preserved in django.db.models.loading until that module is deprecated.
2013-12-17 10:17:44 +01:00
Aymeric Augustin 8662654d6d Removed module-level functions for the app cache.
Since the original ones in django.db.models.loading were kept only for
backwards compatibility, there's no need to recreate them. However, many
internals of Django still relied on them.

They were also imported in django.db.models. They never appear in the
documentation, except a quick mention of get_models and get_app in the
1.2 release notes to document an edge case in GIS. I don't think that
makes them a public API.

This commit doesn't change the overall amount of global state but
clarifies that it's tied to the app_cache object instead of hiding it
behind half a dozen functions.
2013-12-17 10:17:44 +01:00
Aymeric Augustin 860c2c8bc5 Moved django.db.models.loading to django.apps.cache.
This commit doesn't contain any code changes; it's purely a refactoring.
2013-12-17 10:17:43 +01:00
Loic Bistuer 6685713869 Fixed E127 pep8 warnings. 2013-12-14 11:59:15 -05:00
Aymeric Augustin 9c5f59f489 Brought comments in sync with the code in BaseAppCache. 2013-12-11 23:16:06 +01:00
Simon Charette 75924cfa6d Fixed #21563 -- Single related object descriptors should work with `hasattr`.
Thanks to Aymeric Augustin for the review and Trac alias monkut for the report.
2013-12-11 12:49:28 -05:00
Loic Bistuer a2814846ca Fixed E124 pep8 warnings. 2013-12-10 15:12:48 -05:00
Alex Gaynor ffc0e0ca37 Corrected a flake8 issue -- this line is imported for the purpose of re-exposing the name 2013-12-06 13:22:53 -06:00
Roger Hu bbc73e6a12 Fixed #21566 -- Fixed AttributeError when using bulk_create with ForeignObject. 2013-12-06 20:20:16 +01:00
pegler 38e24d680d Fixed #21554 -- Incorrect SQL generated when using multiple inheritance. 2013-12-06 14:12:38 -05:00
Baptiste Mispelon 621c25c419 Added missing deconstruct() methods. 2013-12-06 15:23:34 +01:00
Baptiste Mispelon 19e4374971 Fixed ModelState breaking when unique_together has unhashable elements. 2013-12-06 15:22:52 +01:00
Baptiste Mispelon 54d9e3ccf6 Fixed error in ManyToManyField.deconstruct(). 2013-12-06 15:22:52 +01:00
Andrew Godwin df800b1609 Add clone() method to Field to get clean copies of it. 2013-12-04 13:55:45 +00:00
Alex Hill ec73ce5d8a Fixed comment typos. 2013-11-30 07:59:32 -05:00
Loic Bistuer f563c339ca Fixed #20867 -- Added the Form.add_error() method.
Refs #20199 #16986.

Thanks @akaariai, @bmispelon, @mjtamlyn, @timgraham for the reviews.
2013-11-30 01:00:53 +07:00
Loic Bistuer 91fce675a4 Use 'update_fields' in RelatedManager.clear() when bulk=False.
Thanks Simon Charette for the suggestion.

Refs #21169.
2013-11-29 03:01:08 +07:00
Christopher Medrela 7477a4ffde Fixed E125 pep8 warnings 2013-11-28 08:50:11 -05:00
Loic Bistuer f450bc9f44 Added a bulk option to RelatedManager remove() and clear() methods
Refs #21169
2013-11-27 19:45:22 +02:00
Anssi Kääriäinen 52015b963d Used simpler queries for m2m clearing when possible.
Refs #21169
2013-11-27 19:45:05 +02:00
Loic Bistuer 17c3997f68 Fixed #21169 -- Reworked RelatedManager methods use default filtering
The `remove()` and `clear()` methods of the related managers created by
`ForeignKey`, `GenericForeignKey`, and `ManyToManyField` suffered from a
number of issues. Some operations ran multiple data modifying queries without
wrapping them in a transaction, and some operations didn't respect default
filtering when it was present (i.e. when the default manager on the related
model implemented a custom `get_queryset()`).

Fixing the issues introduced some backward incompatible changes:

- The implementation of `remove()` for `ForeignKey` related managers changed
  from a series of `Model.save()` calls to a single `QuerySet.update()` call.
  The change means that `pre_save` and `post_save` signals aren't called anymore.

- The `remove()` and `clear()` methods for `GenericForeignKey` related
  managers now perform bulk delete so `Model.delete()` isn't called anymore.

- The `remove()` and `clear()` methods for `ManyToManyField` related
  managers perform nested queries when filtering is involved, which may
  or may not be an issue depending on the database and the data itself.

Refs. #3871, #21174.

Thanks Anssi Kääriäinen and Tim Graham for the reviews.
2013-11-27 19:44:18 +02:00
Simon Charette eb38257e51 Fixed #21391 -- Allow model signals to lazily reference their senders. 2013-11-24 17:51:22 -05:00
Baptiste Mispelon 331d79a77d Fixed #21469 -- Allow set objects in Meta.unique_together.
Thanks to Tim for the review.
2013-11-20 17:26:26 +01:00
Alex Gaynor 10a09b8e60 Fixed the use of the -ise suffix, where -ize is prefered 2013-11-15 05:23:14 -08:00
Loic Bistuer 32e75803be Fixed typo and slightly improved error message when db is missing time zone definitions.
Refs #21432.
2013-11-15 10:55:29 +07:00
Loic Bistuer 17ed99f3a3 Fixed #21432 -- DateTimeQuery now copies tzinfo when cloning.
Thanks Enrique Martínez for the report and @bmispelon for the tests.
2013-11-14 21:36:55 +01:00
Loic Bistuer cb83448891 Fixed #21410 -- prefetch_related() for ForeignKeys with related_name='+'
Regression introduced by commit 9777442.

Thanks to trac username troygrosfield for the report and test case.
2013-11-13 07:35:34 +02:00
Loic Bistuer f51c1f5900 Fixed #17001 -- Custom querysets for prefetch_related.
This patch introduces the Prefetch object which allows customizing prefetch
operations.

This enables things like filtering prefetched relations, calling select_related
from a prefetched relation, or prefetching the same relation multiple times
with different querysets.

When a Prefetch instance specifies a to_attr argument, the result is stored
in a list rather than a QuerySet. This has the fortunate consequence of being
significantly faster. The preformance improvement is due to the fact that we
save the costly creation of a QuerySet instance.

Thanks @akaariai for the original patch and @bmispelon and @timgraham
for the reviews.
2013-11-07 14:49:49 +02:00
Anssi Kääriäinen b1b04df065 Fixed #20600 -- ordered distinct(*fields) in subqueries 2013-11-07 14:29:50 +02:00
Anssi Kääriäinen ccbba98131 Removed non-necessary code in Compiler._setup_joins() 2013-11-07 12:57:02 +02:00
Anssi Kääriäinen ba6c9fae45 Removed Query.setup_joins() and join() argument outer_if_first.
Instead always create new joins as OUTER.
2013-11-07 12:57:02 +02:00
Anssi Kääriäinen 6fe2b001db Fixed #21376 -- New implementation for query join promotion logic
This commit introduced a new class JoinPromoter that can be used to
abstract away join promotion problems for complex filter conditions.
Query._add_q() and Query.combine() now use the new class.

Also, added a lot of comments about why join promotion is done the way
it is.

Thanks to Tim Graham for original report and testing the changes, and
for Loic Bistuer for review.
2013-11-07 12:53:26 +02:00
Alex Gaynor c347f78cc1 Fixed all E226 violations 2013-11-03 10:08:55 -08:00
Alex Gaynor 91078f5669 Merge pull request #1861 from milmazz/E251
Fixed flake8 E251 violations
2013-11-03 09:42:31 -08:00
Florian Apolloner f40f90d63b Fixed regressions from 36ded01527.
Refs #21302
2013-11-03 12:45:15 +01:00
Milton Mazzarri cbc7cbbc5b Fixed flake8 E251 violations 2013-11-03 03:22:11 -06:00
coagulant 3bc0d46a84 Fixed all E261 warnings 2013-11-02 18:20:39 -04:00
Anssi Kääriäinen bec0b2a8c6 Fixed #14511 -- bug in .exclude() query 2013-11-02 22:35:45 +02:00
Alex Gaynor 7548aa8ffd More attacking E302 violators 2013-11-02 13:12:09 -07:00
Tim Graham 36ded01527 Fixed #21302 -- Fixed unused imports and import *. 2013-11-02 15:24:56 -04:00
Anssi Kääriäinen b44d42be6d Fixed #21366 -- regression in join promotion logic
The regression was caused by ecaba36028
and affected OR connected filters.
2013-11-02 20:44:19 +02:00
Florian Hahn 5240b83462 Fixed #17027 -- Added support for the power operator in F expressions.
Thanks dan at dlo.me for the initial patch.

- Added __pow__ and __rpow__ to ExpressionNode
- Added oracle and mysql specific power expressions
- Added used-defined power function for sqlite
2013-10-22 10:29:57 -04:00
Anssi Kääriäinen 86c248aa64 Fixed #21249 -- variable name typo in compiler.get_grouping()
The typo could have consequences in exceptional cases, but I didn't
figure out a way to actually produce such a case, so not tests.

Report & patch by Michael Manfre.
2013-10-21 22:08:53 +03:00
Alasdair Nicol b289fcf1bf Fixed #21288 -- Fixed E126 pep8 warnings 2013-10-21 08:31:30 -04:00
Loic Bistuer 584110417f Fixed #21283 -- Added support for migrations if models is a package.
Thanks Markus Holtermann for the report.
2013-10-19 09:48:57 -04:00
Alasdair Nicol dfb4cb9970 Fixed #21285 -- Fixed E121,E122 pep8 warnings 2013-10-17 20:20:11 -04:00
Anssi Kääriäinen 3a66035107 Removed F.__deepcopy__()
The method didn't change standard __deepcopy__ in any way.
2013-10-17 17:45:56 +03:00
Marc Tamlyn 349c12d3f5 Fixed #16855 -- select_related() chains as expected.
select_related('foo').select_related('bar') is now equivalent to
select_related('foo', 'bar').

Also reworded docs to recommend select_related(*fields) over select_related()
2013-10-15 15:59:36 +01:00
Aymeric Augustin 589dc49e12 Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible.
Thanks jpic for the report and chmodas for working on a patch.

Reverts 2ea80b94. Refs #19362.
2013-10-13 18:14:04 +02:00
Aymeric Augustin 570d9c2678 Fixed #19560 -- Identified field in warning for naive datetime.
Thanks gcc for the report and vajrasky for the patch.
2013-10-13 11:54:11 +02:00
Tim Graham b67ab75e82 Fixed assorted flake8 errors. 2013-10-11 07:25:14 -04:00
Tim Graham adedc31072 Fixed "redefinition of unused 'foo' from line X" pyflakes warnings. 2013-10-10 11:09:42 -04:00
Javed Khan 4dbd95ad65 Fixed #21236 -- Allowed migrations to work with unique_together tuples.
Thanks hjwp for the report.
2013-10-07 09:39:14 -04:00
Anssi Kääriäinen 1df3c49a1a Fixed #21174 -- transaction control in related manager methods 2013-10-05 23:07:52 +03:00
Anssi Kääriäinen 93cc6dcdac Fixed #18414 -- qs.exists() for sliced distinct queries 2013-10-05 21:40:36 +03:00
Anssi Kääriäinen ecaba36028 Improved Query join promotion logic
There were multiple cases where join promotion was a bit too aggressive.
This resulted in using outer joins where not necessary.

Refs #21150.
2013-10-05 14:52:17 +03:00
Simon Charette 948d209ada Fixed #21217 -- Avoid connecting `(pre|post)_init` signals to abstract senders. 2013-10-04 16:23:06 -04:00
Simon Charette fa2e1371cd Fixed #21216 -- Allow `OneToOneField` reverse accessor to be hidden. 2013-10-03 13:20:05 -04:00
Anssi Kääriäinen bf13c75c0d Fixed #21203 -- resolve_columns fields misalignment
In queries using .defer() together with .select_related() the values
and fields arguments didn't align properly for resolve_columns().
2013-10-01 20:29:23 +03:00
Anssi Kääriäinen d64060a736 OrderedDict creation avoidance for .values() queries
Avoid accessing query.extra and query.aggregates directly for .values()
queries. Refs #20950.
2013-10-01 10:56:13 +03:00
Loic Bistuer d847ddfe1d Fixed #3871 -- Fixed regression introduced by 04a2a6b.
Added do_not_call_in_templates=True attribute to RelatedManagers
to prevent them from being called.

Thanks jbg@ for the report.
2013-09-30 15:43:44 -04:00
Aymeric Augustin 728548e483 Fixed #21134 -- Prevented queries in broken transactions.
Squashed commit of the following:

commit 63ddb271a44df389b2c302e421fc17b7f0529755
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date:   Sun Sep 29 22:51:00 2013 +0200

    Clarified interactions between atomic and exceptions.

commit 2899ec299228217c876ba3aa4024e523a41c8504
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date:   Sun Sep 22 22:45:32 2013 +0200

    Fixed TransactionManagementError in tests.

    Previous commit introduced an additional check to prevent running
    queries in transactions that will be rolled back, which triggered a few
    failures in the tests. In practice using transaction.atomic instead of
    the low-level savepoint APIs was enough to fix the problems.

commit 4a639b059ea80aeb78f7f160a7d4b9f609b9c238
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date:   Tue Sep 24 22:24:17 2013 +0200

    Allowed nesting constraint_checks_disabled inside atomic.

    Since MySQL handles transactions loosely, this isn't a problem.

commit 2a4ab1cb6e83391ff7e25d08479e230ca564bfef
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date:   Sat Sep 21 18:43:12 2013 +0200

    Prevented running queries in transactions that will be rolled back.

    This avoids a counter-intuitive behavior in an edge case on databases
    with non-atomic transaction semantics.

    It prevents using savepoint_rollback() inside an atomic block without
    calling set_rollback(False) first, which is backwards-incompatible in
    tests.

    Refs #21134.

commit 8e3db393853c7ac64a445b66e57f3620a3fde7b0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date:   Sun Sep 22 22:14:17 2013 +0200

    Replaced manual savepoints by atomic blocks.

    This ensures the rollback flag is handled consistently in internal APIs.
2013-09-30 09:42:27 +02:00
Russell Keith-Magee 9595183d03 Fixed #13724: Corrected routing of write queries involving managers.
Previously, if a database request spanned a related object manager, the
first manager encountered would cause a request to the router, and this
would bind all subsequent queries to the same database returned by the
router. Unfortunately, the first router query would be performed using
a read request to the router, resulting in bad routing information being
used if the subsequent query was actually a write.

This change defers the call to the router until the final query is acutally
made.

It includes a small *BACKWARDS INCOMPATIBILITY* on an edge case - see the
release notes for details.

Thanks to Paul Collins (@paulcollinsiii) for the excellent debugging
work and patch.
2013-09-30 13:05:43 +08:00
Erik Romijn 1a63092981 Fixed #20439 -- Started deprecation of IPAddressField 2013-09-28 10:55:32 +02:00
Loic Bistuer 04a2a6b0f9 Fixed #3871 -- Custom managers when traversing reverse relations. 2013-09-25 21:15:59 +03:00
Anssi Kääriäinen 83554b018e Fixed #21126 -- QuerySet value conversion failure
A .annotate().select_related() query resulted in misaligned rows vs
columns for compiler.resolve_columns() method.

Report & patch by Michael Manfre.
2013-09-25 20:47:57 +03:00
Anssi Kääriäinen 9027da65d3 Added '*' to quote_cache
The commit for #18333 missed quote_cache default value for *.
Refs #18333.
2013-09-24 23:00:31 +03:00
Michael Manfre 9a041807fc Fixed #18333 - Quoted annotated column names 2013-09-24 10:10:08 -04:00
Andrei Picus 8e737cf282 Fix small grammatical error in comment.
Changed 'there are no filtering' to 'there is no filtering'.
2013-09-24 14:55:05 +03:00
Aymeric Augustin a5b062576b Removed a few trailing backslashes.
We have always been at war with trailing backslashes.
2013-09-22 14:04:10 +02:00
Anssi Kääriäinen 50633e7353 Fixed #12568 -- no error when accessing custom field's descriptor
The SubfieldBase's descriptor caused an AttributeError when accessed
from the class. Introspection didn't like that.

Patch by Trac alias supervacuo.
2013-09-18 10:03:52 +03:00
Tim Graham 18ffdb1772 Fixed #17627 -- Renamed util.py files to utils.py
Thanks PaulM for the suggestion and Luke Granger-Brown and
Wiktor Kołodziej for the initial patch.
2013-09-16 12:52:05 -04:00
Anssi Kääriäinen ff723d894d Fixed #20950 -- Instantiate OrderedDict() only when needed
The use of OrderedDict (even an empty one) was surprisingly slow. By
initializing OrderedDict only when needed it is possible to save
non-trivial amount of computing time (Model.save() is around 30% faster
for example).

This commit targetted sql.Query only, there are likely other places
which could use similar optimizations.
2013-09-14 20:52:17 +03:00
Loic Bistuer d59f1993f1 Made MigrationWriter look for a "deconstruct" attribute on functions.
Refs #20978.
2013-09-10 10:12:23 -04:00
Loic Bistuer 5df8f749e6 Fixed #20978 -- Made deletion.SET_NULL more friendly for MigrationWriter.serialize. 2013-09-10 10:12:23 -04:00
Alex Gaynor 0ee8aa5c39 Removed an unused local var 2013-09-08 07:42:16 -07:00
Aymeric Augustin 31e16c1343 Negligible style fix. 2013-09-07 13:48:37 -05:00
Aymeric Augustin b4cd8169de Fixed #11811 -- Data-loss bug in queryset.update.
It's now forbidden to call queryset.update(field=instance) when instance
hasn't been saved to the database ie. instance.pk is None.
2013-09-06 17:15:23 -05:00
Aymeric Augustin 73f38eb4d1 Minor factorization. 2013-09-06 17:15:23 -05:00
Chris Wilson eade315da1 Fixed #10164 -- Made AutoField increase monotonically on SQLite
Thanks malte for the report.
2013-09-06 12:31:17 -04:00
Aymeric Augustin 365c3e8b73 Replaced "not PY3" by "PY2", new in six 1.4.0. 2013-09-02 12:11:02 +02:00
Carl Meyer 7211741fc5 Fixed #20999 - Allow overriding formfield class with choices, without subclass restrictions.
Refs #18162. Thanks claudep and mjtamlyn for review.
2013-08-30 17:43:10 -06:00
Simon Charette 11cd7388f7 Fixed #20989 -- Removed useless explicit list comprehensions. 2013-08-30 10:57:51 -04:00
Anssi Kääriäinen e973ee6a98 Fixed #20988 -- Added model meta option select_on_save
The option can be used to force pre 1.6 style SELECT on save behaviour.
This is needed in case the database returns zero updated rows even if
there is a matching row in the DB. One such case is PostgreSQL update
trigger that returns NULL.

Reviewed by Tim Graham.

Refs #16649
2013-08-30 09:41:07 +03:00
Anssi Kääriäinen 13be3bfef1 Removed stale add_q() comment 2013-08-30 09:45:32 +03:00
Tim Graham c7d0ff0cad Fixed #20989 -- Removed explicit list comprehension inside dict() and tuple()
Thanks jeroen.pulles at redslider.net for the suggestion and
helper script.
2013-08-29 12:11:03 -04:00
Tim Graham f19a3669b8 Fixed #14786 -- Fixed get_db_prep_lookup calling get_prep_value twice if prepared is False.
Thanks homm for the report and Aramgutang and lrekucki for work on
the patch.
2013-08-29 11:13:34 -04:00
Andrew Godwin 5569b0b92f Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	django/db/backends/oracle/base.py
	django/db/backends/postgresql_psycopg2/base.py
	django/db/models/signals.py
	tests/queries/tests.py
2013-08-23 12:36:53 +01:00
Anssi Kääriäinen 6af05e7a0f Fixed model.__eq__ and __hash__ for no pk value cases
The __eq__ method now considers two instances without primary key value
equal only when they have same id(). The __hash__ method raises
TypeError for no primary key case.

Fixed #18864, fixed #18250

Thanks to Tim Graham for docs review.
2013-08-22 17:24:07 +03:00
Anssi Kääriäinen 8d65b6082c Fixed #20955 -- select_related regression
In cases where the same connection (from model A to model B along the
same field) was needed multiple times in a select_related query, the
join setup code mistakenly reused an existing join.
2013-08-22 10:51:07 +03:00
Tim Graham 3f416f6379 Fixed a regression with get_or_create and virtual fields.
refs #20429

Thanks Simon Charette for the report and review.
2013-08-21 22:32:04 +01:00
Anssi Kääriäinen 244e2b71f5 Fixed #20946 -- model inheritance + m2m failure
Cleaned up the internal implementation of m2m fields by removing
related.py _get_fk_val(). The _get_fk_val() was doing the wrong thing
if asked for the foreign key value on foreign key to parent model's
primary key when child model had different primary key field.
2013-08-21 22:32:04 +01:00
Anssi Kääriäinen f5552571dc Fixed #20820 -- Model inheritance + m2m fixture loading regression
Tests by Tim Graham, report from jeroen.pulles@redslider.net.
2013-08-21 22:31:50 +01:00
Anssi Kääriäinen cea7204504 Fixed #14056 -- Made sure LEFT JOIN aren't trimmed in ORDER BY
If LEFT JOINs are required for correct results, then trimming the join
can lead to incorrect results. Consider case:

TBL A: ID | TBL B: ID  A_ID
       1           1   1
       2
Now A.order_by('b__a') did use a join to B, and B's a_id column. This
was seen to contain the same value as A's id, and so the join was
trimmed. But this wasn't correct as the join is LEFT JOIN, and for row
A.id = 2 the B.a_id column is NULL.
2013-08-21 22:30:46 +01:00
Simon Charette 63378163f9 Fixed #20943 -- Weakly reference senders when caching their associated receivers 2013-08-21 22:30:45 +01:00
Tim Graham f7290581fe Fixed a regression with get_or_create and virtual fields.
refs #20429

Thanks Simon Charette for the report and review.
2013-08-21 08:30:21 -04:00
Anssi Kääriäinen b065aeb17f Fixed #20946 -- model inheritance + m2m failure
Cleaned up the internal implementation of m2m fields by removing
related.py _get_fk_val(). The _get_fk_val() was doing the wrong thing
if asked for the foreign key value on foreign key to parent model's
primary key when child model had different primary key field.
2013-08-21 08:32:19 +03:00
Anssi Kääriäinen 1ed77e7782 Fixed #20820 -- Model inheritance + m2m fixture loading regression
Tests by Tim Graham, report from jeroen.pulles@redslider.net.
2013-08-20 16:54:05 +03:00
Anssi Kääriäinen 905409855c Fixed #14056 -- Made sure LEFT JOIN aren't trimmed in ORDER BY
If LEFT JOINs are required for correct results, then trimming the join
can lead to incorrect results. Consider case:

TBL A: ID | TBL B: ID  A_ID
       1           1   1
       2
Now A.order_by('b__a') did use a join to B, and B's a_id column. This
was seen to contain the same value as A's id, and so the join was
trimmed. But this wasn't correct as the join is LEFT JOIN, and for row
A.id = 2 the B.a_id column is NULL.
2013-08-20 10:55:00 +03:00
Simon Charette e55ca60903 Fixed #20943 -- Weakly reference senders when caching their associated receivers 2013-08-20 01:53:58 -04:00
Andrew Godwin b6a957f0ba Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	docs/ref/django-admin.txt
2013-08-19 18:30:48 +01:00
Anssi Kääriäinen 7bc57a6d71 Fixed #11881 -- removed junk from aggregation subqueries
There were clauses that weren't needed in the subqueries. These were
ORDER BY, SELECT FOR UPDATE and related selections.
2013-08-19 16:15:09 +03:00
Anssi Kääriäinen 7737305a4f Fixed #12886 -- aggregation over sliced queryset 2013-08-19 16:00:17 +03:00
Andrew Godwin 52edc16086 Add more stringent M2M tests and fix the bug they exposed 2013-08-19 13:50:26 +01:00
Anssi Kääriäinen 4668c142dc Made Model.__eq__ consider proxy models equivalent
Fixed #11892, fixed #16458, fixed #14492.
2013-08-19 09:51:28 +03:00
Loic Bistuer 163a34ce4b Fixed #20883 -- Made model inheritance find parent links in abstract parents 2013-08-13 15:14:11 +03:00
Anssi Kääriäinen dcdc579d16 Fixed #20874 -- bump_prefix() in nested subqueries
Also made some cleanup to build_filter() code by introducing submethods
solve_lookup_type() and prepare_lookup_value().
2013-08-13 14:11:52 +03:00
Andrew Godwin 588b523233 Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	django/db/models/options.py
2013-08-09 14:37:37 +01:00
Tim Graham ddae74b64c Fixed #9057 -- Added default_permissions model meta option.
Thanks hvendelbo for the suggestion and koenb for the draft patch.
2013-08-09 09:19:52 -04:00
Andrew Godwin de64c4d6e9 Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	django/core/management/commands/flush.py
	django/core/management/commands/syncdb.py
	django/db/models/loading.py
	docs/internals/deprecation.txt
	docs/ref/django-admin.txt
	docs/releases/1.7.txt
2013-08-09 14:17:30 +01:00
Anssi Kääriäinen c7739e30b2 Fixed #17424 -- annotate() + exclude() bug
The bug was already fixed by 01b9c3d519,
so only tests added.

At the same time promote_joins()'s uncoditional flag is gone, it isn't
needed for anything any more.
2013-08-07 12:53:33 +03:00
Alex Cucu 1c64a0f29e Fixed #19918 -- Modified select_for_update to run on the write database. 2013-08-06 09:50:59 -04:00
Tim Graham 04489c7dbf Fixed #17667 -- Prevented app loading from skipping nonexistent apps after the first try
Thanks ea2100@ for the report and akaariai for the patch.
2013-08-05 13:34:35 -04:00
Curtis Maloney 07876cf02b Deprecated SortedDict (replaced with collections.OrderedDict)
Thanks Loic Bistuer for the review.
2013-08-04 07:09:39 -04:00
Tim Graham 5df84b268d Removed unused model option "admin" 2013-08-01 10:27:30 -04:00
Alex Couper 1123f45511 Fixed #20649 -- Allowed blank field display to be defined in the initial list of choices. 2013-07-31 14:12:03 -04:00
Loic Bistuer acd1d439fd Fixed #20826 -- Moved Manager.raw() and Manager._insert() to the QuerySet class. 2013-07-31 09:54:00 -04:00
Florian Hahn e888a9b30d Fixed #15624 -- Made sure aggregations are present in SELECT 2013-07-31 16:27:58 +03:00
Anssi Kääriäinen c21e86ab9e Added field.attname to Options.name_map
The change also removed allow_explicit_fk from sql/query.py.
2013-07-31 16:02:36 +03:00
Tai Lee 31e6d58d46 Fixed #20348 -- Consistently handle Promise objects in model fields.
All Promise objects were passed to force_text() deep in ORM query code.
Not only does this make it difficult or impossible for developers to
prevent or alter this behaviour, but it is also wrong for non-text
fields.

This commit changes `Field.get_prep_value()` from a no-op to one that
resolved Promise objects. All subclasses now call super() method first
to ensure that they have a real value to work with.
2013-07-31 15:54:17 +03:00
Andrew Godwin 68e0a169c4 Rename pre_ and post_syncdb to *_migrate, with aliases from old names 2013-07-30 11:52:52 +01:00
Claude Paroz 5c1143910e Removed most of absolute_import imports
Should be unneeded with Python 2.7 and up.
Added some unicode_literals along the way.
2013-07-29 20:28:13 +02:00
Claude Paroz fdd7a355bf Deprecated django.utils.importlib
This was a shim for pre-Python 2.7 support.
2013-07-29 17:10:22 +02:00
Julien Phalip 47c755327b Fixed a number of minor misspellings. 2013-07-27 18:46:03 -07:00
Anssi Kääriäinen 7cca8d56d2 Fixed related model lookup regression
It has been possible to use models of wrong type in related field
lookups. For example pigs__in=[a_duck] has worked. Changes to
ForeignObject broke that.

It might be a good idea to restrict the model types usable in lookups.
This should be done intentionally, not accidentally and without any
consideration for deprecation path.
2013-07-26 13:13:27 +03:00
Loic Bistuer 31fadc1202 Fixed #20625 -- Chainable Manager/QuerySet methods.
Additionally this patch solves the orthogonal problem that specialized
`QuerySet` like `ValuesQuerySet` didn't inherit from the current `QuerySet`
type. This wasn't an issue until now because we didn't officially support
custom `QuerySet` but it became necessary with the introduction of this new
feature.

Thanks aaugustin, akaariai, carljm, charettes, mjtamlyn, shaib and timgraham
for the reviews.
2013-07-26 12:41:27 +03:00
Anssi Kääriäinen 92476e880c Fixed ._meta.pk_index() virtual field failure 2013-07-25 16:25:23 +03:00
Tim Graham 31c13a99bb Fixed #14300 -- Fixed initial SQL location if models is a package.
Thanks al_the_x for the report and fheinz for the draft patch.
2013-07-24 06:56:33 -04:00
ersran9 311c1d2848 Fixed #20761 -- Reworded ForeignKey default error message 2013-07-23 22:16:31 +02:00
Tim Graham ad98b985aa Fixed test failures introduced in e716518ad2
refs #20761
2013-07-23 15:21:29 -04:00
Loic Bistuer e716518ad2 Fixed #20761 -- Fixed DatabaseError handling in get_or_create and update_or_create. 2013-07-23 09:20:43 -04:00
Anssi Kääriäinen 6b4967e883 Minor change to get_extra_descriptor_filter()
Refs #20611.
2013-07-23 15:34:29 +03:00
Anssi Kääriäinen 4bd5554721 Fixed #20782 -- qs.values().aggregate() failure
In the combination of .values().aggregate() the aggregate_select_mask
didn't include the aggregates added. This resulted in bogus query.

Thanks to Trac alias debanshuk for report.
2013-07-23 11:38:38 +03:00
Andrew Godwin 03ec3219a0 Merge branch 'master' into schema-alteration
Conflicts:
	django/db/backends/mysql/introspection.py
	django/db/backends/oracle/creation.py
	django/db/backends/postgresql_psycopg2/creation.py
	django/db/models/base.py
	django/db/models/loading.py
2013-07-22 19:04:25 +01:00
Tim Graham 2333c9662b Fixed #14007 -- Added model discovery in models module without the need to specify app_label.
Thanks mark@ and Aramgutang for work on the patch.
2013-07-16 19:32:30 -04:00
Tim Graham 2456ffa42c Fixed #20746 -- Removed Python 2.6 specific code/docs 2013-07-14 13:02:55 -04:00
Tim Graham f2cb94f1c0 Fixed #20740 -- GenericIPAddressField should pass protocol to formfield()
Thanks Jeff250.
2013-07-12 16:05:14 -04:00
Karol Sikora 6272d2f155 Fixed #20429 -- Added QuerySet.update_or_create
Thanks tunixman for the suggestion and Loic Bistuer for the review.
2013-07-12 08:26:35 -04:00
Tim Graham 95eb68c98f Fixed #17339 -- Factor out has_result into database backend.
Thanks jonash.
2013-07-09 06:41:52 -04:00
Tim Graham da79ccca1d Fixed #6785 -- Made QuerySet.get() fetch a limited number of rows.
Thanks Patryk Zawadzki.
2013-07-08 08:33:40 -04:00
Alex Gaynor 03d9566e0d A large number of stylistic cleanups across django/db/ 2013-07-08 10:39:54 +10:00
Alex Gaynor c8c22ccdcb Removed some logic that wasn't needed following removal of some deprecated code. 2013-07-08 08:49:58 +10:00
Andrew Godwin b1e0ec06f0 Merge branch 'master' into schema-alteration 2013-07-02 10:49:53 +01:00
Aymeric Augustin d5589b4cd3 Removed some conditional code only needed under Python 2.6. 2013-07-01 12:02:17 +02:00
Alex Gaynor b9ebca6a28 Removed a comment that wasn't adding a value.
In the intervening years, RelatedField has become less of a hack (though it still is one). Anyone who wants to can re-instate the comment, but please add more details.
2013-06-30 23:32:23 -07:00
Aymeric Augustin acd7b34aaf Advanced deprecation warnings for Django 1.7. 2013-06-29 18:49:37 +02:00
Claude Paroz ea3fe78a9d Fixed #20660 -- Do not try to delete an unset FieldFile
Thanks stanislas.guerra at gmail.com for the report and
Baptiste Mispelon for the review.
2013-06-29 18:08:39 +02:00
Ramiro Morales 6ba69c8456 Removed 'depth' .select_related() argument as per deprecation TL. 2013-06-28 21:48:16 -03:00
Andrew Godwin 904b82759c Fix Python 3 support 2013-06-28 17:53:49 +01:00
Andrew Godwin 7a47ba6f6a Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	django/db/backends/__init__.py
	django/db/models/fields/related.py
	tests/field_deconstruction/tests.py
2013-06-28 17:32:57 +01:00
Andrew Godwin 48dd1e63bb Ported over Field.deconstruct() from my schema alteration branch.
This is to help other ongoing branches which would benefit from
this functionality.
2013-06-28 17:27:52 +01:00
Shai Berger d097417025 Support 'pyformat' style parameters in raw queries, Refs #10070
Add support for Oracle, fix an issue with the repr of RawQuerySet,
add tests and documentations. Also added a 'supports_paramstyle_pyformat'
database feature, True by default, False for SQLite.

Thanks Donald Stufft for review of documentation.
2013-06-28 06:59:10 +03:00
Andrew Godwin 99b467f272 Add related_query_name to ForeignKey/M2M. Refs #20244 2013-06-27 14:44:21 +01:00
Simon Charette b91787910c Fixed #20642 -- Deprecated `Option.get_(add|change|delete)_permission`.
Those methods were only used by `contrib.admin` internally and exclusively
related to `contrib.auth`. Since they were undocumented but used
in the wild the raised deprecation warning point to an also undocumented
alternative that lives in `contrib.auth`.

Also did some PEP8 and other cleanups in the affected modules.
2013-06-25 12:22:37 -04:00
Andrew Godwin 48493cff73 Remove EmailField max_length default removal in deconstruct() 2013-06-22 12:56:37 +01:00
Andrew Godwin 9daf81b94e Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	django/db/models/loading.py
2013-06-19 12:05:23 +01:00
Florian Hahn 2f35c6f10f Fixed #14930 -- values_list() failure on qs ordered by extra column
Thanks lsaffre for the report and simon29, vicould, and Florian Hahn
for the patch.

Some changes done by committer.
2013-06-18 23:56:51 +03:00
Loic Bistuer ee77d4b253 Fixed #20199 -- Allow ModelForm fields to override error_messages from model fields 2013-06-18 08:01:17 -04:00
Loic Bistuer f34cfec0fa Refactored ValidationError to allow persisting error params and error codes as the exception bubbles up 2013-06-18 08:01:17 -04:00
Anssi Kääriäinen aa22cbd51a Fixed #20583 -- ORM always uses setup_joins() for join generation
There were a couple of places which used Query.join() directly. By
using setup_joins() in these places the code is more DRY, and in
addition there is no need to directly call field.get_joining_columns()
unless the field is the given join_field from get_path_info(). This
makes it easier to make sure a ForeignObject subclass generates joins
correctly in all cases.
2013-06-16 15:44:52 +03:00
Anssi Kääriäinen 5459795ef2 Fixed #20289 -- pickling of dynamic models 2013-06-14 17:05:54 +03:00
Anssi Kääriäinen 89bf7a4525 Fixed #20528 -- regression in select_related join promotion
The join used by select_related was incorrectly INNER when the query
had an ORed filter for nullable join that was trimmed away. Fixed this
by forcing the join type to LOUTER even when a join was trimmed away
in ORed queries.
2013-06-14 16:29:06 +03:00
Baptiste Mispelon dc9c359546 Fixed #20594 -- Add validation to models.SlugField.
Thanks carbonXT for the report.
2013-06-13 13:31:57 -04:00
Aymeric Augustin 4daf570b98 Added TransactionTestCase.available_apps.
This can be used to make Django's test suite significantly faster by
reducing the number of models for which content types and permissions
must be created and tables must be flushed in each non-transactional
test.

It's documented for Django contributors and committers but it's branded
as a private API to preserve our freedom to change it in the future.

Most of the credit goes to Anssi. He got the idea and did the research.

Fixed #20483.
2013-06-10 11:24:10 +02:00
Aymeric Augustin 79ff1aedd5 Replaced a dict emulating a set with a set. 2013-06-09 14:31:04 +02:00
Andrew Godwin 3c296382b8 Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
	django/db/models/fields/related.py
2013-06-07 11:15:34 +01:00
Anssi Kääriäinen 31fd64ad8a Fixed #20564 -- Generic relations exclude() regression
The patch for #19385 caused a regression in certain generic relations
.exclude() filters if a subquery was needed. The fix contains a
refactoring to how Query.split_exclude() and Query.trim_start()
interact.

Thanks to Trac alias nferrari for the report.
2013-06-06 01:54:46 +03:00
Aymeric Augustin b55624a026 Added get_app_paths() to the AppCache.
This method is useful to discover files inside apps.
2013-06-02 20:39:45 +02:00
Dan Loewenherz 07a73a2714 Fixed #20337 -- Clarified error message when database relation is not allowed. 2013-06-01 07:55:49 -04:00
Tim Graham 5074c75a37 Fixed #16856 - Added a way to clear select_related.
Thanks Carl for the suggestion and David Cramer for the patch.
2013-05-30 11:06:05 -04:00
Tim Graham 616f3c4a79 Fixed #20272 - Moved update_fields existence check into Model._do_update.
Thanks Gavin Wahl.
2013-05-30 10:48:30 -04:00
Tai Lee 69f7db153d Fixed #16436 -- defer + annotate + select_related crash
Correctly calculate the ``aggregate_start`` offset from loaded fields,
if any are deferred, instead of ``self.query.select`` which includes all
fields on the model.

Also made some PEP 8 fixes.
2013-05-30 08:46:31 +03:00
Tim Graham 90af278203 Fixed #16137 - Removed kwargs requirement for QuerySet.get_or_create
Thanks wilfred@, poirier, and charettes for work
on the patch.
2013-05-27 10:01:14 -04:00
Tim Graham 6f8627dd7f Fixed #17582 - Added message to DoesNotExist exceptions.
Thanks simon@ for the suggestion and JordanPowell
for the initial patch.
2013-05-27 07:57:06 -04:00
Anssi Kääriäinen d467e11785 Fixed #20507 -- SubqueryConstraint alias relabeling
The SubqueryConstraint defined relabeled_clone(), but that was never
called. Instead there is now clone() and relabel_aliases() methods for
SubqueryConstraint.

A related problem was that SubqueryConstraint didn't correctly use
quote_name_unless_alias() of the outer query. This resulted in failures
when running under PostgreSQL.
2013-05-27 12:25:29 +03:00
Ramiro Morales 0fa8d43e74 Replaced `and...or...` constructs with PEP 308 conditional expressions. 2013-05-26 23:47:50 -03:00
Luke Plant 17559e6eb0 Optimisation in prefetch_related_objects 2013-05-24 11:19:44 +01:00
Luke Plant 4fd94969d8 Fixed #19607 - prefetch_related crash
Thanks to av@rdf.ru and flarno11@yahoo.de for the report.
2013-05-24 11:10:48 +01:00
Donald Stufft 3de1288042 Fixed #11398 - Added a pre_syncdb signal 2013-05-23 01:09:22 -04:00
Aymeric Augustin 0e51d8eb66 Fixed #20463 -- Made get_or_create more robust.
When an exception other than IntegrityError was raised, get_or_create
could fail and leave the database connection in an unusable state.

Thanks UloPe for the report.
2013-05-22 10:56:06 +02:00
Anssi Kääriäinen 70679243d1 Fixed #18702 -- Removed chunked reads from QuerySet iteration 2013-05-21 19:51:59 +03:00
Selwin Ong ea9a0857d4 Fixed #19326 -- Added first() and last() methods to QuerySet 2013-05-21 18:52:28 +03:00
Ramiro Morales 4ba1c2e785 Fixed #9321 -- Deprecated hard-coding of help text in model ManyToManyField fields.
This is backward incompatible for custom form field/widgets that rely
on the hard-coded 'Hold down "Control", or "Command" on a Mac, to select
more than one.' sentence.

Application that use standard model form fields and widgets aren't
affected but need to start handling these help texts by themselves
before Django 1.8.

For more details, see the related release notes and deprecation timeline
sections added with this commit.
2013-05-20 16:29:51 -03:00
Anssi Kääriäinen 266c0bb23e Fixed #20278 -- ensured .get() exceptions do not recurse infinitely
A regression caused by d5b93d3281 made .get() error
reporting recurse infinitely on certain rare conditions. Fixed this by
not trying to print the given lookup kwargs.
2013-05-20 18:50:40 +03:00
Anssi Kääriäinen c9a96075fa Fixed #20378 -- regression in GenericRelation on abstract model
When a GenericRelation was defined on abstract model, queries on childs
of the abstract model didn't work. The problem was in the way fields and
in particular field.rel was copied from models to their children.

The regression was likely caused by #19385. Thanks to Gavin Wahl for
spotting the regression.
2013-05-20 18:02:10 +03:00
Anssi Kääriäinen f53059b411 Fixed qs.values() regression when used in subquery 2013-05-20 15:38:47 +03:00