question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'NoneType' object has no attribute 'generated'

See original GitHub issue

Describe the bug Can’t create a model with custom pk (id) data type (TextField).

Some part of pytest log:

def __init__(self, **kwargs) -> None:
        # self._meta is a very common attribute lookup, lets cache it.
        meta = self._meta
>       self._saved_in_db = meta.pk_attr in kwargs and meta.pk.generated
E       AttributeError: 'NoneType' object has no attribute 'generated'

To Reproduce

class UserModel(Model):
    id: str = fields.TextField(pk=True, generated=False)
    email: str = fields.CharField(index=True, unique=True, null=False, max_length=255)
    hashed_password: str = fields.CharField(null=False, max_length=255)
    is_active: bool = fields.BooleanField(default=True, null=False)
    is_superuser: bool = fields.BooleanField(default=False, null=False)

    class Meta:
        table = "user"

Expected behavior All work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AEnterprisecommented, Nov 26, 2019

yes but it doesn’t take a generated value at all because it isn’t valid. it doesn’t want generated, true or false, because it can’t do anything with it. in the context of of a ``TextField´´ the concept of auto-generating values doesn’t exist, so it doesn’t accept configuration options for it as there is no point in accepting options it can’t do anything with

0reactions
grigicommented, Dec 20, 2019

Released v0.15.6 with DeprecationWarning when using TextField as primary key with suggestion to use CharField instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do I get AttributeError: 'NoneType' object has no attribute ...
NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None .
Read more >
[FIXED] AttributeError: 'NoneType' object has no attribute ...
Hence, AttributeError: 'NoneType' object has no attribute 'something' error occurs when the type of object you are referencing is None.
Read more >
AttributeError: 'NoneType' object has no attribute ... - GitHub
In my case the problem was caused by adding a module directory to sys path and using import directory.module . Using import module...
Read more >
AttributeError: 'NoneType' object has no attribute 'dtype'
When trying to start the Training, I get the following Error: AttributeError: 'NoneType' object has no attribute 'dtype'.
Read more >
AttributeError: 'NoneType' object has no attribute 'call' on ...
Hello, I'm at a loss to explain why this flow fails and succeeds at the same time… It only consists in triggering a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found