{"id":449,"date":"2013-07-09T14:29:52","date_gmt":"2013-07-09T18:29:52","guid":{"rendered":"http:\/\/dashdrum.com\/blog\/?p=449"},"modified":"2013-07-12T10:01:22","modified_gmt":"2013-07-12T14:01:22","slug":"factory-boy-and-django-software-updates","status":"publish","type":"post","link":"https:\/\/dashdrum.com\/blog\/2013\/07\/factory-boy-and-django-software-updates\/","title":{"rendered":"Factory Boy and Django: Software Updates"},"content":{"rendered":"<p><a href=\"http:\/\/argenteditions.com\/carryingin-boy-alexandria-glass-factory-p-14.html#.UdxWSD6G2Bg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/argenteditions.com\/images\/large\/\/lewis-hine\/lewis-hine-child-labor-factory-boy-01293-700.jpg\" width=\"700\" height=\"480\" alt=\"Turn of the Century boy in a factory\" class=\"aligncenter\" \/><\/a><\/p>\n<p>I&#8217;ve been using <a href=\"https:\/\/factoryboy.readthedocs.org\/en\/latest\/index.html#\">Factory Boy<\/a> in all of my tests for a while, but I hadn&#8217;t upgraded the package since setting up my development machine in December of last year. This meant I have been happily chugging along with v1.20.<\/p>\n<p>Today I started the task of upgrading my applications to Django v1.5, so I ran <code>pip install --upgrade<\/code> on my requirements file. Django moved up to v1.5 just fine, but Factory Boy also jumped up to v2.11. I hadn&#8217;t noticed that some new features and several deprecations were added in v1.3, and many changes happened for v2.0.<\/p>\n<h2>DjangoModelFactory<\/h2>\n<p>The first odd behavior I noticed was that the model instances created by the factories weren&#8217;t being saved, and I also had trouble adding data to ManyToMany relationships even after I explicitly saved them. Turns out there was a major change to the Factory class. Rather than use that generic class, we are now being directed to use DjangoModelFactory.<\/p>\n<p>The error I was seeing was a recursion problem, so it took a while to track down.<\/p>\n<h2>Sequence<\/h2>\n<p>Next, all of my Sequence calls were failing &#8211; telling me that I couldn&#8217;t use a string operation on a type of &#8216;int&#8217;. In this case the problem was that the default data type for a sequence was changed to &#8216;int&#8217;. Since &#8216;str&#8217; was the former default (although not necessarily documented), my solution was to declare the type as &#8216;str&#8217;.<\/p>\n<pre><code>name = factory.Sequence(lambda n: 'Location ' + n, str)\n<\/code><\/pre>\n<p>I&#8217;m a big fan of this package for tests, and I am glad that it is a very active project. Read through the <a href=\"https:\/\/github.com\/rbarrois\/factory_boy\/blob\/master\/docs\/changelog.rst#id99\">change log<\/a> for more info on these and many other updates.<\/p>\n<p>I promise to do a better job of keeping up with the changes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been using Factory Boy in all of my tests for a while, but I hadn&#8217;t upgraded the package since setting up my development machine in December of last year. This meant I have been happily chugging along with v1.20. Today I started the task of upgrading my applications to Django v1.5, so I ran &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/dashdrum.com\/blog\/2013\/07\/factory-boy-and-django-software-updates\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Factory Boy and Django: Software Updates&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":4,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":457,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions\/457"}],"wp:attachment":[{"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dashdrum.com\/blog\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}