Reject constant defaults on primary-key attributes
Mantenedores costumam responder em até 5 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 84/100
Direção de pesquisa
Comece por compile_attribute em declare.py e acompanhe como os valores padrão dos atributos de chave primária são classificados. Adicione testes para valores padrão constantes de chaves, valores padrão CURRENT_TIMESTAMP de chaves e valores padrão inalterados de atributos secundários. O trabalho estará concluído quando valores padrão constantes de chaves forem rejeitados na declaração com um erro que nomeie o atributo e informe aos usuários que removam o valor padrão, enquanto os valores padrão gerados e secundários continuem sendo aceitos.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Problem
The definition language accepts a constant default on a primary-key attribute. compile_attribute in declare.py rejects only nullable key attributes; any other default above the --- separator compiles to NOT NULL DEFAULT <value>.
A constant default lets an insertion omit part of an entity's identity. The database then fills in the same value for every such insertion: the first one succeeds silently with the default key, and the next one collides.
Reproduction
DataJoint 2.3.5.dev, MySQL 8.0:
@schema
class Probe(dj.Manual):
definition = """
probe_id = 1 : int32
---
label : varchar(16)
"""
Probe.insert1({"label": "x"}) # accepted, no key supplied
Probe.to_dicts() # [{'probe_id': 1, 'label': 'x'}]
Proposed rule
- Reject constant defaults on primary-key attributes at declaration, with an error naming the attribute.
- Keep allowing generated defaults, values produced afresh at each insertion.
CURRENT_TIMESTAMPis the one the definition language accepts today, andvisit_ts = CURRENT_TIMESTAMP : datetimein the key works as a generated key. A generated UUID default would fall under the same rule if it is ever supported.
Generated keys remain surrogates, with the costs the docs already describe in Explicit keys, no auto-increment: a repeated insertion makes a second entity instead of a key collision. They are allowed but not recommended.
This matches the rule in the Relational Workflow Model specification: key attributes are never null and take no constant default; a nullable attribute's only default is null; an attribute without a default must be supplied.
Scope
- The check runs at declaration time only, so existing tables are unaffected. A schema that declares a key attribute with a constant default will fail to declare after the change, which is the intent; the error message should say to remove the default.
- Foreign-key attributes in the key are unaffected, since dependencies take no defaults.
Tests
- A declaration with
k = 1 : int32above the separator raises. - A declaration with
ts = CURRENT_TIMESTAMP : datetimeabove the separator succeeds. - Defaults on secondary attributes are unchanged.
- Linguagem predominante
- Python
- Estrelas
- 198
- Forks
- 103
- Merge médio
- 5d 1h
- PRs com merge (30d)
- 12
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de datajoint/datajoint-python
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
datajoint/datajoint-python#1750 ·
Mantenedores costumam responder em até 5 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1747 ·
Mantenedores costumam responder em até 5 dias
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorTalvez já em andamento @godara-alt assumiu há 3 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1703 ·
Mantenedores costumam responder em até 5 dias
-
Character matrices with more than one row come back transposed from <blob>Talvez já em andamento @godara-alt assumiu há 2 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1702 ·
Mantenedores costumam responder em até 5 dias
-
staged_insert1 stores object paths with the class name and an empty store name, so garbage collection can delete its objectsTalvez já em andamento @godara-alt assumiu há 3 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
datajoint/datajoint-python#1701 ·
Mantenedores costumam responder em até 5 dias
Todas as issues de datajoint/datajoint-python
Issues semelhantes
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
jxxghp/MoviePilot#7576 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
jbaruch/software-factory#266 ·
Mantenedores costumam responder em até 1 dia
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia