{"action":"created","issue":{"url":"https://api.github.com/repos/FactoryBoy/factory_boy/issues/448","repository_url":"https://api.github.com/repos/FactoryBoy/factory_boy","labels_url":"https://api.github.com/repos/FactoryBoy/factory_boy/issues/448/labels{/name}","comments_url":"https://api.github.com/repos/FactoryBoy/factory_boy/issues/448/comments","events_url":"https://api.github.com/repos/FactoryBoy/factory_boy/issues/448/events","html_url":"https://github.com/FactoryBoy/factory_boy/issues/448","id":293114032,"number":448,"title":"Factory classes accept only model attribute names as variables","user":{"login":"cho-leukeleu","id":20397882,"avatar_url":"https://avatars0.githubusercontent.com/u/20397882?v=4","gravatar_id":"","url":"https://api.github.com/users/cho-leukeleu","html_url":"https://github.com/cho-leukeleu","followers_url":"https://api.github.com/users/cho-leukeleu/followers","following_url":"https://api.github.com/users/cho-leukeleu/following{/other_user}","gists_url":"https://api.github.com/users/cho-leukeleu/gists{/gist_id}","starred_url":"https://api.github.com/users/cho-leukeleu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cho-leukeleu/subscriptions","organizations_url":"https://api.github.com/users/cho-leukeleu/orgs","repos_url":"https://api.github.com/users/cho-leukeleu/repos","events_url":"https://api.github.com/users/cho-leukeleu/events{/privacy}","received_events_url":"https://api.github.com/users/cho-leukeleu/received_events","type":"User","site_admin":false},"labels":[{"id":30490576,"url":"https://api.github.com/repos/FactoryBoy/factory_boy/labels/Q&A","name":"Q&A","color":"DDDDDD","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-01-31T10:55:11Z","updated_at":"2018-02-11T18:54:43Z","closed_at":"2018-02-11T18:54:43Z","author_association":"NONE","body":"Hi and thanks for this nice faking tool !\r\n\r\nI ran into a strange behaviour today. Apparently all variables used within a factory class need to exist as an attribute in the model it's faking.\r\n\r\nInitializing `treatment_state` this way:\r\n```python\r\nclass ClientFactory(UserProfileFactory):\r\n    class Meta:\r\n        model = Client\r\n        django_get_or_create = ('user',)\r\n\r\n    treatment_state = factory.Faker('random_element', elements=[st for st, _ in TREATMENT_STATES])\r\n```\r\nwill raise this error\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/christineho/Documents/dev.vm1/project/current_instance/project/tests/test_selenium/test_flow.py\", line 30, in setUp\r\n    user__first_name='JanSmit'\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/base.py\", line 46, in __call__\r\n    return cls.create(**kwargs)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/base.py\", line 568, in create\r\n    return cls._generate(enums.CREATE_STRATEGY, kwargs)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/base.py\", line 505, in _generate\r\n    return step.build()\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/builder.py\", line 279, in build\r\n    kwargs=kwargs,\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/base.py\", line 314, in instantiate\r\n    return self.factory._create(model, *args, **kwargs)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/django.py\", line 163, in _create\r\n    return cls._get_or_create(model_class, *args, **kwargs)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/factory/django.py\", line 154, in _get_or_create\r\n    instance, _created = manager.get_or_create(*args, **key_fields)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/django/db/models/manager.py\", line 85, in manager_method\r\n    return getattr(self.get_queryset(), name)(*args, **kwargs)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/django/db/models/query.py\", line 459, in get_or_create\r\n    lookup, params = self._extract_model_params(defaults, **kwargs)\r\n  File \"/Users/christineho/.virtualenvs/project/lib/python2.7/site-packages/django/db/models/query.py\", line 534, in _extract_model_params\r\n    \"', '\".join(sorted(invalid_params)),\r\nFieldError: Invalid field name(s) for model Client: 'st'.\r\n```\r\nwhile this would work fine\r\n```\r\ntreatment_state = factory.Faker('random_element', elements=[treatment_state for treatment_state, _ in TREATMENT_STATES])\r\n```\r\n\r\nLet me know if you need more info."},"comment":{"url":"https://api.github.com/repos/FactoryBoy/factory_boy/issues/comments/364777070","html_url":"https://github.com/FactoryBoy/factory_boy/issues/448#issuecomment-364777070","issue_url":"https://api.github.com/repos/FactoryBoy/factory_boy/issues/448","id":364777070,"user":{"login":"rbarrois","id":694541,"avatar_url":"https://avatars0.githubusercontent.com/u/694541?v=4","gravatar_id":"","url":"https://api.github.com/users/rbarrois","html_url":"https://github.com/rbarrois","followers_url":"https://api.github.com/users/rbarrois/followers","following_url":"https://api.github.com/users/rbarrois/following{/other_user}","gists_url":"https://api.github.com/users/rbarrois/gists{/gist_id}","starred_url":"https://api.github.com/users/rbarrois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbarrois/subscriptions","organizations_url":"https://api.github.com/users/rbarrois/orgs","repos_url":"https://api.github.com/users/rbarrois/repos","events_url":"https://api.github.com/users/rbarrois/events{/privacy}","received_events_url":"https://api.github.com/users/rbarrois/received_events","type":"User","site_admin":false},"created_at":"2018-02-11T18:54:42Z","updated_at":"2018-02-11T18:54:42Z","author_association":"OWNER","body":"Looks like this solved your issue; please reopen the issue otherwise ;)"}}
{"actor":{"display_login":"rbarrois"}}