PrimaryKeyCreator, no parameter are passed to the create_pk method
See original GitHub issueI want to make an MurmurHash class to create a primary key for a new model instance. I did this class that adheres to the PrimaryKeyCreator protocol:
# https://github.com/hajimes/mmh3
import mmh3
class Mmh3PrimaryKey:
"""
A client-side generated primary key that follows the MurmurHash (MurmurHash3) spec.
https://en.wikipedia.org/wiki/MurmurHash
"""
@staticmethod
def create_pk(self, *args, **kwargs) -> str:
return str('some argument in args / kwargs')
and set Meta primary_key_creator_cls like this:
class ErrorServer(HashModel):
local_hostname: str
class Meta:
primary_key_creator_cls = Mmh3PrimaryKey
But when I instantiate ErrorServerclass
, no parameter (len of *args, **kwargs == 0) are passed to create_pk
es = ErrorServer(local_hostname='my_hostname', param2='Test')
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
SerialSerialKeyCreator (Oracle - Berkeley DB Java Edition API)
A abstract key creator that uses a serial key and a serial data entry. ... Creates the index key object from primary key...
Read more >PUT parameter into IDENTITY(1,1) property in SQL Table ...
CREATE TABLE Pets ( PetId int IDENTITY(@Parameter,1) PRIMARY KEY, PetName varchar(255) );. My SQL parser does not accept such syntax. sql-server ...
Read more >CREATE FUNCTION (Transact-SQL) - Microsoft Learn
Specify a parameter name by using an at sign (@) as the first character. The parameter name must comply with the rules for...
Read more >Example: CREATE Request with Presence or Absence of PRIMARY ...
This example specifies neither an explicit PRIMARY INDEX clause nor an explicit NO PRIMARY INDEX clause, but does specify a UNIQUE constraint on...
Read more >Db2 12 - Db2 SQL - CREATE TABLE - IBM
Provides a shorthand method of defining a primary key composed of a single column. Thus, if PRIMARY KEY is specified in the definition...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also need to change the default pk. I use this workaround. Works fine for me.
I am also interested in changing the default primary key and noticed the same behavior.
I also noticed that the custom class
FieldInfo
(inherited from Pydantic FieldInfo) has the attribute “primary_key” which is used in the RedisModel class to initiate the default fieldpk
as primary key.But apparently this attribute cannot be used elsewhere:
It would be great to use this parameter like SQL Alchemy ORM to change the default behavior. If we use this parameter manually in another field (declared one time in the model), the latter must have precedence over the pk field. What do you think?