Reject constant defaults on primary-key attributes
Los mantenedores suelen responder en 5 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
Línea de trabajo
Empieza con compile_attribute en declare.py y sigue cómo se clasifican los valores predeterminados de los atributos de clave primaria. Añade cobertura para valores predeterminados constantes de claves, valores predeterminados CURRENT_TIMESTAMP de claves y valores predeterminados de atributos secundarios sin cambios. La tarea estará completa cuando los valores predeterminados constantes de claves se rechacen durante la declaración con un error que nombre el atributo e indique a los usuarios que eliminen el valor predeterminado, mientras que los valores predeterminados generados y secundarios sigan aceptándose.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 198
- Forks
- 103
- Merge medio
- 5 d 1 h
- PR fusionados (30 d)
- 12
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de datajoint/datajoint-python
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
datajoint/datajoint-python#1750 ·
Los mantenedores suelen responder en 5 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1747 ·
Los mantenedores suelen responder en 5 días
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorPosiblemente ocupada @godara-alt la tomó hace 3 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1703 ·
Los mantenedores suelen responder en 5 días
-
Character matrices with more than one row come back transposed from <blob>Posiblemente ocupada @godara-alt la tomó hace 2 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1702 ·
Los mantenedores suelen responder en 5 días
-
staged_insert1 stores object paths with the class name and an empty store name, so garbage collection can delete its objectsPosiblemente ocupada @godara-alt la tomó hace 3 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1701 ·
Los mantenedores suelen responder en 5 días
Todos los issues de datajoint/datajoint-python
Issues similares
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
jxxghp/MoviePilot#7576 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
jbaruch/software-factory#266 ·
Los mantenedores suelen responder en 1 día
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día