Repository: dj-stripe/dj-stripe

Issue:
Error: Cannot resolve keyword 'customer' into field. 
All,

Cannot get past the step

`python manage.py djstripe_init_customers`

in the installation. 

Running Python 3.6.0, Django 1.11, and the latest version of dj-stripe (1.0.0).

What combination of Django version and dj-stripe version are folks successfully using at the moment? Thanks! 

Here is the traceback:
```
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/jdln/temp/dj-stripe/djstripe/management/commands/djstripe_init_customers.py", line 25, in handle
    for subscriber in get_subscriber_model().objects.filter(customer__isnull=True):
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/query.py", line 781, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/query.py", line 799, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1260, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1286, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1164, in build_filter
    lookups, parts, reffed_expression = self.solve_lookup_type(arg)
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1044, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "/Users/jdln/.virtualenvs/djstripe/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1362, in names_to_path
    "Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword 'customer' into field. Choices are: date_joined, djstripe_customers, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password, user_permissions, username
```


Discussion:
dj-stripe doesn't work on Django 1.11 yet due to the Polymorphic Model dependency. Does this happen on 1.10?
Update from me...

Using 1.10 generated this error:

AttributeError: 'Options' object has no attribute 'get_all_field_names'

But...going back to 1.9 no errors so far. 


Hi @jdlnolen, thanks for reporting this. Can you post the full traceback for that AttributeError?
@kavdev here you go:

```
/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/djstripe/__init__.py:23: UserWarning: dj-stripe deprecation notice: Django 1.7 and lower are no longer
supported. Please upgrade to Django 1.8 or higher.
Reference: https://github.com/pydanny/dj-stripe/issues/275
  warnings.warn(msg)
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/base.py", line 356, in execute
    output = self.handle(*args, **options)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/djstripe/management/commands/djstripe_init_customers.py", line 15, in handle
    for subscriber in get_subscriber_model().objects.filter(customer__isnull=True):
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/djstripe/settings.py", line 94, in get_subscriber_model
    _check_subscriber_for_email_address(subscriber_model, "The customer user model must have an email attribute.")
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/djstripe/settings.py", line 70, in _check_subscriber_for_email_address
    if ("email" not in subscriber_model._meta.get_all_field_names()) and not hasattr(subscriber_model, 'email'):
AttributeError: 'Options' object has no attribute 'get_all_field_names'
```

and here is the dump from pip freeze:

appdirs==1.4.3
dj-stripe==0.8.0
Django==1.10
django-braces==1.11.0
django-model-utils==3.0.0
jsonfield==2.0.1
packaging==16.8
pyparsing==2.2.0
pytz==2017.2
requests==2.13.0
six==1.10.0
stripe==1.53.0
> and the latest version of dj-stripe (1.0.0).

@jdlnolen You sure about that? :)
(fixed in 1.0.0 [here](https://github.com/kavdev/dj-stripe/blob/1.0.0/djstripe/settings.py#L138))
@kavdev doh! sorry for the goof, trying to get a clean env to show the error. 

Now...with 1.0.0 installed, this is the error:

```
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/core/management/base.py", line 356, in execute
    output = self.handle(*args, **options)
  File "/Users/jdln/temp/dj-stripe/djstripe/management/commands/djstripe_init_customers.py", line 25, in handle
    for subscriber in get_subscriber_model().objects.filter(customer__isnull=True):
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/query.py", line 794, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/query.py", line 812, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1227, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1253, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1133, in build_filter
    lookups, parts, reffed_expression = self.solve_lookup_type(arg)
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1019, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "/Users/jdln/.virtualenvs/dj3/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1327, in names_to_path
    "Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword 'customer' into field. Choices are: date_joined, djstripe_customers, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password, user_permissions, username
```

let me know if you need more info...
Yeah that line looks wrong: `for subscriber in get_subscriber_model().objects.filter(customer__isnull=True):`
and that is with django 1.10 
@jleclanche yep, that broke when we switched to a ``customers`` ForeignKey. That line should probably be:
```python
for subscriber in get_subscriber_model().objects.filter(customers=None)
```

(untested). We probably also want to fit livemode in there somehow
Really this is just another "we need to get syncing fixed" issue
@kavdev  Just to give it a shot I tried your suggested change it still failed, but then I noticed that the error output says one of the valid options is djstripe_customers, so I tried this:

```python
for subscriber in get_subscriber_model().objects.filter(djstripe_customers=None):
```

I ran `python manage.py djstripe_init_customers` and it completed successfully. 

I have very limited knowledge of this project, but if you think that looks like the fix, I'm happy to submit a PR.
@W7PEA yep, that's the fix. This was changed after we realized there could be confusion between djstripe customers and stripe customers.

https://github.com/dj-stripe/dj-stripe/blob/1.0.0/djstripe/models.py#L158

Resolving patch:
diff --git a/djstripe/management/commands/djstripe_init_customers.py b/djstripe/management/commands/djstripe_init_customers.py
--- a/djstripe/management/commands/djstripe_init_customers.py
+++ b/djstripe/management/commands/djstripe_init_customers.py
@@ -22,7 +22,7 @@ class Command(BaseCommand):
 
     def handle(self, *args, **options):
         """Create Customer objects for Subscribers without Customer objects associated."""
-        for subscriber in get_subscriber_model().objects.filter(customer__isnull=True):
+        for subscriber in get_subscriber_model().objects.filter(djstripe_customers=None):
             # use get_or_create in case of race conditions on large subscriber bases
             Customer.get_or_create(subscriber=subscriber)
             print("Created subscriber for {0}".format(subscriber.email))


Test patch: