Comments (10)
What field class are you using for last_seen
?
from walrus.
@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.
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.
@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.
@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.
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.
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.
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.
@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.
Not a problem, I'm sorry I didn't notice it sooner myself. Glad it's working now.
from walrus.
Related Issues (20)
- cache.cached doesn't work if the function returns None HOT 1
- "lock.event:" pollution HOT 4
- [feature]Any plan for supporting model relationship mapping? HOT 1
- Consumer group pending exception HOT 1
- VSCode type checking can't identify RedisPy's Redis as parent HOT 2
- Database() is falsy when database is empty HOT 2
- Empty queries in graph HOT 1
- A problem with query in graph.py HOT 1
- Lock event keys never expire HOT 1
- There is a problem. HOT 3
- Walrus Support for Redis Python Client 4.x+ HOT 2
- Is Expiring Hashes supported in Walrus? HOT 3
- Missing argument in method calling
- Support from_url database connection HOT 2
- Extending Containers with custom behavior HOT 1
- Not compatible with Redis Python Client 5.0.0 HOT 5
- examples in docs use Python 2 syntax
- Handling json HOT 3
- regex error HOT 1
- regex syntax warning
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from walrus.