tests.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. # -*- coding: utf-8 -*-
  2. # Unittests for fixtures.
  3. from __future__ import absolute_import, unicode_literals
  4. import os
  5. import re
  6. from django.core.serializers.base import DeserializationError
  7. from django.core import management
  8. from django.core.management.base import CommandError
  9. from django.core.management.commands.dumpdata import sort_dependencies
  10. from django.db import transaction, IntegrityError
  11. from django.db.models import signals
  12. from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
  13. skipUnlessDBFeature)
  14. from django.test.utils import override_settings
  15. from django.utils.encoding import force_text
  16. from django.utils._os import upath
  17. from django.utils import six
  18. from django.utils.six import PY3, StringIO
  19. import json
  20. from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
  21. Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
  22. ExternalDependency, Thingy)
  23. class TestFixtures(TestCase):
  24. def animal_pre_save_check(self, signal, sender, instance, **kwargs):
  25. self.pre_save_checks.append(
  26. (
  27. 'Count = %s (%s)' % (instance.count, type(instance.count)),
  28. 'Weight = %s (%s)' % (instance.weight, type(instance.weight)),
  29. )
  30. )
  31. def test_duplicate_pk(self):
  32. """
  33. This is a regression test for ticket #3790.
  34. """
  35. # Load a fixture that uses PK=1
  36. management.call_command(
  37. 'loaddata',
  38. 'sequence',
  39. verbosity=0,
  40. commit=False
  41. )
  42. # Create a new animal. Without a sequence reset, this new object
  43. # will take a PK of 1 (on Postgres), and the save will fail.
  44. animal = Animal(
  45. name='Platypus',
  46. latin_name='Ornithorhynchus anatinus',
  47. count=2,
  48. weight=2.2
  49. )
  50. animal.save()
  51. self.assertGreater(animal.id, 1)
  52. def test_loaddata_not_found_fields_not_ignore(self):
  53. """
  54. Test for ticket #9279 -- Error is raised for entries in
  55. the serialised data for fields that have been removed
  56. from the database when not ignored.
  57. """
  58. with self.assertRaises(DeserializationError):
  59. management.call_command(
  60. 'loaddata',
  61. 'sequence_extra',
  62. verbosity=0
  63. )
  64. def test_loaddata_not_found_fields_ignore(self):
  65. """
  66. Test for ticket #9279 -- Ignores entries in
  67. the serialised data for fields that have been removed
  68. from the database.
  69. """
  70. management.call_command(
  71. 'loaddata',
  72. 'sequence_extra',
  73. ignore=True,
  74. verbosity=0,
  75. commit=False
  76. )
  77. self.assertEqual(Animal.specimens.all()[0].name, 'Lion')
  78. @skipIfDBFeature('interprets_empty_strings_as_nulls')
  79. def test_pretty_print_xml(self):
  80. """
  81. Regression test for ticket #4558 -- pretty printing of XML fixtures
  82. doesn't affect parsing of None values.
  83. """
  84. # Load a pretty-printed XML fixture with Nulls.
  85. management.call_command(
  86. 'loaddata',
  87. 'pretty.xml',
  88. verbosity=0,
  89. commit=False
  90. )
  91. self.assertEqual(Stuff.objects.all()[0].name, None)
  92. self.assertEqual(Stuff.objects.all()[0].owner, None)
  93. @skipUnlessDBFeature('interprets_empty_strings_as_nulls')
  94. def test_pretty_print_xml_empty_strings(self):
  95. """
  96. Regression test for ticket #4558 -- pretty printing of XML fixtures
  97. doesn't affect parsing of None values.
  98. """
  99. # Load a pretty-printed XML fixture with Nulls.
  100. management.call_command(
  101. 'loaddata',
  102. 'pretty.xml',
  103. verbosity=0,
  104. commit=False
  105. )
  106. self.assertEqual(Stuff.objects.all()[0].name, '')
  107. self.assertEqual(Stuff.objects.all()[0].owner, None)
  108. def test_absolute_path(self):
  109. """
  110. Regression test for ticket #6436 --
  111. os.path.join will throw away the initial parts of a path if it
  112. encounters an absolute path.
  113. This means that if a fixture is specified as an absolute path,
  114. we need to make sure we don't discover the absolute path in every
  115. fixture directory.
  116. """
  117. load_absolute_path = os.path.join(
  118. os.path.dirname(upath(__file__)),
  119. 'fixtures',
  120. 'absolute.json'
  121. )
  122. management.call_command(
  123. 'loaddata',
  124. load_absolute_path,
  125. verbosity=0,
  126. commit=False
  127. )
  128. self.assertEqual(Absolute.load_count, 1)
  129. def test_unknown_format(self):
  130. """
  131. Test for ticket #4371 -- Loading data of an unknown format should fail
  132. Validate that error conditions are caught correctly
  133. """
  134. with six.assertRaisesRegex(self, management.CommandError,
  135. "Problem installing fixture 'bad_fixture1': "
  136. "unkn is not a known serialization format."):
  137. management.call_command(
  138. 'loaddata',
  139. 'bad_fixture1.unkn',
  140. verbosity=0,
  141. commit=False,
  142. )
  143. @override_settings(SERIALIZATION_MODULES={'unkn': 'unexistent.path'})
  144. def test_unimportable_serializer(self):
  145. """
  146. Test that failing serializer import raises the proper error
  147. """
  148. with six.assertRaisesRegex(self, ImportError,
  149. r"No module named.*unexistent"):
  150. management.call_command(
  151. 'loaddata',
  152. 'bad_fixture1.unkn',
  153. verbosity=0,
  154. commit=False,
  155. )
  156. def test_invalid_data(self):
  157. """
  158. Test for ticket #4371 -- Loading a fixture file with invalid data
  159. using explicit filename.
  160. Validate that error conditions are caught correctly
  161. """
  162. with six.assertRaisesRegex(self, management.CommandError,
  163. "No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)"):
  164. management.call_command(
  165. 'loaddata',
  166. 'bad_fixture2.xml',
  167. verbosity=0,
  168. commit=False,
  169. )
  170. def test_invalid_data_no_ext(self):
  171. """
  172. Test for ticket #4371 -- Loading a fixture file with invalid data
  173. without file extension.
  174. Validate that error conditions are caught correctly
  175. """
  176. with six.assertRaisesRegex(self, management.CommandError,
  177. "No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)"):
  178. management.call_command(
  179. 'loaddata',
  180. 'bad_fixture2',
  181. verbosity=0,
  182. commit=False,
  183. )
  184. def test_empty(self):
  185. """
  186. Test for ticket #4371 -- Loading a fixture file with no data returns an error.
  187. Validate that error conditions are caught correctly
  188. """
  189. with six.assertRaisesRegex(self, management.CommandError,
  190. "No fixture data found for 'empty'. \(File format may be invalid.\)"):
  191. management.call_command(
  192. 'loaddata',
  193. 'empty',
  194. verbosity=0,
  195. commit=False,
  196. )
  197. def test_error_message(self):
  198. """
  199. (Regression for #9011 - error message is correct)
  200. """
  201. with six.assertRaisesRegex(self, management.CommandError,
  202. "^No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)$"):
  203. management.call_command(
  204. 'loaddata',
  205. 'bad_fixture2',
  206. 'animal',
  207. verbosity=0,
  208. commit=False,
  209. )
  210. def test_pg_sequence_resetting_checks(self):
  211. """
  212. Test for ticket #7565 -- PostgreSQL sequence resetting checks shouldn't
  213. ascend to parent models when inheritance is used
  214. (since they are treated individually).
  215. """
  216. management.call_command(
  217. 'loaddata',
  218. 'model-inheritance.json',
  219. verbosity=0,
  220. commit=False
  221. )
  222. self.assertEqual(Parent.objects.all()[0].id, 1)
  223. self.assertEqual(Child.objects.all()[0].id, 1)
  224. def test_close_connection_after_loaddata(self):
  225. """
  226. Test for ticket #7572 -- MySQL has a problem if the same connection is
  227. used to create tables, load data, and then query over that data.
  228. To compensate, we close the connection after running loaddata.
  229. This ensures that a new connection is opened when test queries are
  230. issued.
  231. """
  232. management.call_command(
  233. 'loaddata',
  234. 'big-fixture.json',
  235. verbosity=0,
  236. commit=False
  237. )
  238. articles = Article.objects.exclude(id=9)
  239. self.assertEqual(
  240. list(articles.values_list('id', flat=True)),
  241. [1, 2, 3, 4, 5, 6, 7, 8]
  242. )
  243. # Just for good measure, run the same query again.
  244. # Under the influence of ticket #7572, this will
  245. # give a different result to the previous call.
  246. self.assertEqual(
  247. list(articles.values_list('id', flat=True)),
  248. [1, 2, 3, 4, 5, 6, 7, 8]
  249. )
  250. def test_field_value_coerce(self):
  251. """
  252. Test for tickets #8298, #9942 - Field values should be coerced into the
  253. correct type by the deserializer, not as part of the database write.
  254. """
  255. self.pre_save_checks = []
  256. signals.pre_save.connect(self.animal_pre_save_check)
  257. try:
  258. management.call_command(
  259. 'loaddata',
  260. 'animal.xml',
  261. verbosity=0,
  262. commit=False,
  263. )
  264. self.assertEqual(
  265. self.pre_save_checks,
  266. [
  267. ("Count = 42 (<%s 'int'>)" % ('class' if PY3 else 'type'),
  268. "Weight = 1.2 (<%s 'float'>)" % ('class' if PY3 else 'type'))
  269. ]
  270. )
  271. finally:
  272. signals.pre_save.disconnect(self.animal_pre_save_check)
  273. def test_dumpdata_uses_default_manager(self):
  274. """
  275. Regression for #11286
  276. Ensure that dumpdata honors the default manager
  277. Dump the current contents of the database as a JSON fixture
  278. """
  279. management.call_command(
  280. 'loaddata',
  281. 'animal.xml',
  282. verbosity=0,
  283. commit=False,
  284. )
  285. management.call_command(
  286. 'loaddata',
  287. 'sequence.json',
  288. verbosity=0,
  289. commit=False,
  290. )
  291. animal = Animal(
  292. name='Platypus',
  293. latin_name='Ornithorhynchus anatinus',
  294. count=2,
  295. weight=2.2
  296. )
  297. animal.save()
  298. stdout = StringIO()
  299. management.call_command(
  300. 'dumpdata',
  301. 'fixtures_regress.animal',
  302. format='json',
  303. stdout=stdout
  304. )
  305. # Output order isn't guaranteed, so check for parts
  306. data = stdout.getvalue()
  307. # Get rid of artifacts like '000000002' to eliminate the differences
  308. # between different Python versions.
  309. data = re.sub('0{6,}\d', '', data)
  310. animals_data = sorted([
  311. {"pk": 1, "model": "fixtures_regress.animal", "fields": {"count": 3, "weight": 1.2, "name": "Lion", "latin_name": "Panthera leo"}},
  312. {"pk": 10, "model": "fixtures_regress.animal", "fields": {"count": 42, "weight": 1.2, "name": "Emu", "latin_name": "Dromaius novaehollandiae"}},
  313. {"pk": animal.pk, "model": "fixtures_regress.animal", "fields": {"count": 2, "weight": 2.2, "name": "Platypus", "latin_name": "Ornithorhynchus anatinus"}},
  314. ], key=lambda x: x["pk"])
  315. data = sorted(json.loads(data), key=lambda x: x["pk"])
  316. self.maxDiff = 1024
  317. self.assertEqual(data, animals_data)
  318. def test_proxy_model_included(self):
  319. """
  320. Regression for #11428 - Proxy models aren't included when you dumpdata
  321. """
  322. stdout = StringIO()
  323. # Create an instance of the concrete class
  324. widget = Widget.objects.create(name='grommet')
  325. management.call_command(
  326. 'dumpdata',
  327. 'fixtures_regress.widget',
  328. 'fixtures_regress.widgetproxy',
  329. format='json',
  330. stdout=stdout
  331. )
  332. self.assertJSONEqual(
  333. stdout.getvalue(),
  334. """[{"pk": %d, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]"""
  335. % widget.pk
  336. )
  337. def test_loaddata_works_when_fixture_has_forward_refs(self):
  338. """
  339. Regression for #3615 - Forward references cause fixtures not to load in MySQL (InnoDB)
  340. """
  341. management.call_command(
  342. 'loaddata',
  343. 'forward_ref.json',
  344. verbosity=0,
  345. commit=False
  346. )
  347. self.assertEqual(Book.objects.all()[0].id, 1)
  348. self.assertEqual(Person.objects.all()[0].id, 4)
  349. def test_loaddata_raises_error_when_fixture_has_invalid_foreign_key(self):
  350. """
  351. Regression for #3615 - Ensure data with nonexistent child key references raises error
  352. """
  353. with six.assertRaisesRegex(self, IntegrityError,
  354. "Problem installing fixture"):
  355. management.call_command(
  356. 'loaddata',
  357. 'forward_ref_bad_data.json',
  358. verbosity=0,
  359. commit=False,
  360. )
  361. _cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
  362. @override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'),
  363. os.path.join(_cur_dir, 'fixtures_2')])
  364. def test_loaddata_forward_refs_split_fixtures(self):
  365. """
  366. Regression for #17530 - should be able to cope with forward references
  367. when the fixtures are not in the same files or directories.
  368. """
  369. management.call_command(
  370. 'loaddata',
  371. 'forward_ref_1.json',
  372. 'forward_ref_2.json',
  373. verbosity=0,
  374. commit=False
  375. )
  376. self.assertEqual(Book.objects.all()[0].id, 1)
  377. self.assertEqual(Person.objects.all()[0].id, 4)
  378. def test_loaddata_no_fixture_specified(self):
  379. """
  380. Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
  381. """
  382. with six.assertRaisesRegex(self, management.CommandError,
  383. "No database fixture specified. Please provide the path of "
  384. "at least one fixture in the command line."):
  385. management.call_command(
  386. 'loaddata',
  387. verbosity=0,
  388. commit=False,
  389. )
  390. def test_loaddata_not_existant_fixture_file(self):
  391. stdout_output = StringIO()
  392. management.call_command(
  393. 'loaddata',
  394. 'this_fixture_doesnt_exist',
  395. verbosity=2,
  396. commit=False,
  397. stdout=stdout_output,
  398. )
  399. self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
  400. force_text(stdout_output.getvalue()))
  401. class NaturalKeyFixtureTests(TestCase):
  402. def test_nk_deserialize(self):
  403. """
  404. Test for ticket #13030 - Python based parser version
  405. natural keys deserialize with fk to inheriting model
  406. """
  407. management.call_command(
  408. 'loaddata',
  409. 'model-inheritance.json',
  410. verbosity=0,
  411. commit=False
  412. )
  413. management.call_command(
  414. 'loaddata',
  415. 'nk-inheritance.json',
  416. verbosity=0,
  417. commit=False
  418. )
  419. self.assertEqual(
  420. NKChild.objects.get(pk=1).data,
  421. 'apple'
  422. )
  423. self.assertEqual(
  424. RefToNKChild.objects.get(pk=1).nk_fk.data,
  425. 'apple'
  426. )
  427. def test_nk_deserialize_xml(self):
  428. """
  429. Test for ticket #13030 - XML version
  430. natural keys deserialize with fk to inheriting model
  431. """
  432. management.call_command(
  433. 'loaddata',
  434. 'model-inheritance.json',
  435. verbosity=0,
  436. commit=False
  437. )
  438. management.call_command(
  439. 'loaddata',
  440. 'nk-inheritance.json',
  441. verbosity=0,
  442. commit=False
  443. )
  444. management.call_command(
  445. 'loaddata',
  446. 'nk-inheritance2.xml',
  447. verbosity=0,
  448. commit=False
  449. )
  450. self.assertEqual(
  451. NKChild.objects.get(pk=2).data,
  452. 'banana'
  453. )
  454. self.assertEqual(
  455. RefToNKChild.objects.get(pk=2).nk_fk.data,
  456. 'apple'
  457. )
  458. def test_nk_on_serialize(self):
  459. """
  460. Check that natural key requirements are taken into account
  461. when serializing models
  462. """
  463. management.call_command(
  464. 'loaddata',
  465. 'forward_ref_lookup.json',
  466. verbosity=0,
  467. commit=False
  468. )
  469. stdout = StringIO()
  470. management.call_command(
  471. 'dumpdata',
  472. 'fixtures_regress.book',
  473. 'fixtures_regress.person',
  474. 'fixtures_regress.store',
  475. verbosity=0,
  476. format='json',
  477. use_natural_keys=True,
  478. stdout=stdout,
  479. )
  480. self.assertJSONEqual(
  481. stdout.getvalue(),
  482. """[{"pk": 2, "model": "fixtures_regress.store", "fields": {"main": null, "name": "Amazon"}}, {"pk": 3, "model": "fixtures_regress.store", "fields": {"main": null, "name": "Borders"}}, {"pk": 4, "model": "fixtures_regress.person", "fields": {"name": "Neal Stephenson"}}, {"pk": 1, "model": "fixtures_regress.book", "fields": {"stores": [["Amazon"], ["Borders"]], "name": "Cryptonomicon", "author": ["Neal Stephenson"]}}]"""
  483. )
  484. def test_dependency_sorting(self):
  485. """
  486. Now lets check the dependency sorting explicitly
  487. It doesn't matter what order you mention the models
  488. Store *must* be serialized before then Person, and both
  489. must be serialized before Book.
  490. """
  491. sorted_deps = sort_dependencies(
  492. [('fixtures_regress', [Book, Person, Store])]
  493. )
  494. self.assertEqual(
  495. sorted_deps,
  496. [Store, Person, Book]
  497. )
  498. def test_dependency_sorting_2(self):
  499. sorted_deps = sort_dependencies(
  500. [('fixtures_regress', [Book, Store, Person])]
  501. )
  502. self.assertEqual(
  503. sorted_deps,
  504. [Store, Person, Book]
  505. )
  506. def test_dependency_sorting_3(self):
  507. sorted_deps = sort_dependencies(
  508. [('fixtures_regress', [Store, Book, Person])]
  509. )
  510. self.assertEqual(
  511. sorted_deps,
  512. [Store, Person, Book]
  513. )
  514. def test_dependency_sorting_4(self):
  515. sorted_deps = sort_dependencies(
  516. [('fixtures_regress', [Store, Person, Book])]
  517. )
  518. self.assertEqual(
  519. sorted_deps,
  520. [Store, Person, Book]
  521. )
  522. def test_dependency_sorting_5(self):
  523. sorted_deps = sort_dependencies(
  524. [('fixtures_regress', [Person, Book, Store])]
  525. )
  526. self.assertEqual(
  527. sorted_deps,
  528. [Store, Person, Book]
  529. )
  530. def test_dependency_sorting_6(self):
  531. sorted_deps = sort_dependencies(
  532. [('fixtures_regress', [Person, Store, Book])]
  533. )
  534. self.assertEqual(
  535. sorted_deps,
  536. [Store, Person, Book]
  537. )
  538. def test_dependency_sorting_dangling(self):
  539. sorted_deps = sort_dependencies(
  540. [('fixtures_regress', [Person, Circle1, Store, Book])]
  541. )
  542. self.assertEqual(
  543. sorted_deps,
  544. [Circle1, Store, Person, Book]
  545. )
  546. def test_dependency_sorting_tight_circular(self):
  547. self.assertRaisesMessage(
  548. CommandError,
  549. """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
  550. sort_dependencies,
  551. [('fixtures_regress', [Person, Circle2, Circle1, Store, Book])],
  552. )
  553. def test_dependency_sorting_tight_circular_2(self):
  554. self.assertRaisesMessage(
  555. CommandError,
  556. """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
  557. sort_dependencies,
  558. [('fixtures_regress', [Circle1, Book, Circle2])],
  559. )
  560. def test_dependency_self_referential(self):
  561. self.assertRaisesMessage(
  562. CommandError,
  563. """Can't resolve dependencies for fixtures_regress.Circle3 in serialized app list.""",
  564. sort_dependencies,
  565. [('fixtures_regress', [Book, Circle3])],
  566. )
  567. def test_dependency_sorting_long(self):
  568. self.assertRaisesMessage(
  569. CommandError,
  570. """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2, fixtures_regress.Circle3 in serialized app list.""",
  571. sort_dependencies,
  572. [('fixtures_regress', [Person, Circle2, Circle1, Circle3, Store, Book])],
  573. )
  574. def test_dependency_sorting_normal(self):
  575. sorted_deps = sort_dependencies(
  576. [('fixtures_regress', [Person, ExternalDependency, Book])]
  577. )
  578. self.assertEqual(
  579. sorted_deps,
  580. [Person, Book, ExternalDependency]
  581. )
  582. def test_normal_pk(self):
  583. """
  584. Check that normal primary keys still work
  585. on a model with natural key capabilities
  586. """
  587. management.call_command(
  588. 'loaddata',
  589. 'non_natural_1.json',
  590. verbosity=0,
  591. commit=False
  592. )
  593. management.call_command(
  594. 'loaddata',
  595. 'forward_ref_lookup.json',
  596. verbosity=0,
  597. commit=False
  598. )
  599. management.call_command(
  600. 'loaddata',
  601. 'non_natural_2.xml',
  602. verbosity=0,
  603. commit=False
  604. )
  605. books = Book.objects.all()
  606. self.assertEqual(
  607. books.__repr__(),
  608. """[<Book: Cryptonomicon by Neal Stephenson (available at Amazon, Borders)>, <Book: Ender's Game by Orson Scott Card (available at Collins Bookstore)>, <Book: Permutation City by Greg Egan (available at Angus and Robertson)>]"""
  609. )
  610. class TestTicket11101(TransactionTestCase):
  611. def ticket_11101(self):
  612. management.call_command(
  613. 'loaddata',
  614. 'thingy.json',
  615. verbosity=0,
  616. commit=False
  617. )
  618. self.assertEqual(Thingy.objects.count(), 1)
  619. transaction.rollback()
  620. self.assertEqual(Thingy.objects.count(), 0)
  621. transaction.commit()
  622. @skipUnlessDBFeature('supports_transactions')
  623. def test_ticket_11101(self):
  624. """Test that fixtures can be rolled back (ticket #11101)."""
  625. transaction.set_autocommit(False)
  626. try:
  627. self.ticket_11101()
  628. finally:
  629. transaction.set_autocommit(True)