GithubHelp home page GithubHelp logo

Comparing datetime about walrus HOT 10 CLOSED

coleifer avatar coleifer commented on August 18, 2024
Comparing datetime

from walrus.

Comments (10)

coleifer avatar coleifer commented on August 18, 2024

What field class are you using for last_seen?

from walrus.

luisdemarchi avatar luisdemarchi commented on August 18, 2024

@coleifer Following is the actual structure

# Presence REDIS DB (no-SQL)
db = walrus.Database(host='localhost', port=6379, db=0)


class Presence(walrus.Model):
    database = db
    channel_name = walrus.TextField(primary_key=True)
    user = walrus.TextField(fts=True, index=True)
    last_seen = walrus.DateTimeField(default=datetime.datetime.now)
    is_accessible = walrus.BooleanField(index=True, default=False)

from walrus.

coleifer avatar coleifer commented on August 18, 2024

Aha. The problem is the way you are associating the Presence model with the db object.

You should use this instead:

class Presence(walrus.Model):
    __database__ = db  # Double underscores around "database"
    channel_name ... etc.

from walrus.

luisdemarchi avatar luisdemarchi commented on August 18, 2024

@coleifer Sorry, but it's in the documentation if this parameter is not set will take the default. So if I'm wrong the variable should pick the default. I made this change and got several different errors in each of the queries that worked before.

PS: Remembering that I am from Brazil and I am supported by the translator.

>>> Presence.create(channel_name="asdfhkasdlfkjashfdaskjhfsakjhdfa")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Volumes/MacHD/Users/Git/playboy-connect-webservice/.env/lib/python3.6/site-packages/walrus/models.py", line 756, in create
    instance.save()
  File "/Volumes/MacHD/Users/Git/playboy-connect-webservice/.env/lib/python3.6/site-packages/walrus/models.py", line 942, in save
    self.delete(for_update=True)
  File "/Volumes/MacHD/Users/Git/playboy-connect-webservice/.env/lib/python3.6/site-packages/walrus/models.py", line 906, in delete
    original_instance = self.load(hash_key, convert_key=False)
  File "/Volumes/MacHD/Users/Git/playboy-connect-webservice/.env/lib/python3.6/site-packages/walrus/models.py", line 877, in load
    if not cls.database.hash_exists(primary_key):
AttributeError: 'NoneType' object has no attribute 'hash_exists'


>>> for presence in Presence.all():
...     print(presence.last_seen)
...     
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Volumes/MacHD/Users/Git/playboy-connect-webservice/.env/lib/python3.6/site-packages/walrus/models.py", line 777, in all
    for result in cls._query.all_index():
  File "/Volumes/MacHD/Users/Git/playboy-connect-webservice/.env/lib/python3.6/site-packages/walrus/models.py", line 374, in all_index
    return self.model_class.database.Set(self.make_key('all'))
AttributeError: 'NoneType' object has no attribute 'Set'

It is noteworthy that before I could read and write, I just could not return this query. So I find it strange to be a problem connecting to the bank.

from walrus.

coleifer avatar coleifer commented on August 18, 2024

@luisdemarchi -- I think you must be running an older version of walrus. Can you please try upgrading? Depending on how you installed it, you can probably run pip install -U walrus.

from walrus.

luisdemarchi avatar luisdemarchi commented on August 18, 2024

@coleifer:

pip install -U walrus
Requirement already up-to-date: walrus in ./.env/lib/python3.6/site-packages
Requirement already up-to-date: redis in ./.env/lib/python3.6/site-packages (from walrus)

from walrus.

coleifer avatar coleifer commented on August 18, 2024

I'm sorry -- I thought that I had released those changes (database -> __database__) but it turns out that they're just sitting in the master branch right now. So your code is correct for the current release. Reopening this to look into it some more.

from walrus.

coleifer avatar coleifer commented on August 18, 2024

A-ha, I know what the issue is! You need to specify index=True to enable filtering using a field. In your case, the last_seen field needs to have an index.

class Presence(walrus.Model):
    __database__ = db  # If 0.4.0 or newer, use double-underscores.
    channel_name = walrus.TextField(primary_key=True)
    user = walrus.TextField(fts=True, index=True)
    last_seen = walrus.DateTimeField(default=datetime.datetime.now, index=True)  # Add "index=True".
    is_accessible = walrus.BooleanField(index=True, default=False)

Docs: http://walrus.readthedocs.io/en/latest/models.html#filtering-records

from walrus.

luisdemarchi avatar luisdemarchi commented on August 18, 2024

@coleifer Wow! Sorry for this grotesque mistake, this requirement is very clear in its documentation. Thanks a lot for the help. Once the app is ready and published, if possible I'll let you know;)

from walrus.

coleifer avatar coleifer commented on August 18, 2024

Not a problem, I'm sorry I didn't notice it sooner myself. Glad it's working now.

from walrus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.